How to downgrade Dart with Homebrew - dart

I'm on a Mac and I upgraded to Dart 2.8 from Dart 2.7.1 by running
brew upgrade dart
as it describes in the documentation.
However, version 2.8 contains some breaking changes for the Aqueduct framework, so I want to downgrade to Dart 2.7.2.
I tried
brew install dart#2.7.2
but got
Error: No available formula with the name "dart#2.7.2"
I also tried
brew search dart
but only got
dart-lang/dart/dart ✔
dart-lang/dart/dart-beta
dart-lang/dart/dart#1
dart-lang/dart/dart#2
dartsim
There is no option to select a lower 2.x version.
How do I downgrade?

run brew info dart and find the formula link, for example
From: https://github.com/dart-lang/homebrew-dart/blob/master/dart.rb
open the formula link in your browser, it will take you to the master branch repo page
click "Raw" and take the raw url from your browser's address bar, for example
https://raw.githubusercontent.com/dart-lang/homebrew-dart/master/dart.rb
(save the raw url, you will need it in step 5)
go back with your browser to the repo page and click "History"
scroll down until you see the version you're interested in, for example "Updated stable branch to revision 2.7.2"
click on "Updated stable branch to revision 2.7.2" and from the top of the diffs page take the full commit ID (hash) for example fed6de080aef54c4f1c1df732424df37cd3e5a3e
(save the full commit ID (hash), you will need it in step 5)
run brew uninstall dart
install an older version of Dart with
brew install https://raw.githubusercontent.com/dart-lang/homebrew-dart/fed6de080aef54c4f1c1df732424df37cd3e5a3e/dart.rb
In the command above, the url is obtained by using the url you saved in step 2 and replacing the word master with the commit ID (hash) fed6de080aef54c4f1c1df732424df37cd3e5a3e obtained in step 3.
***Note:*** you can keep the older Dart version (for `brew upgrade`) if you pin it with `brew pin dart`

Have a look at the packages fvm and dswitch.
Both let you change between dart versions.
Fvm for the flutter dart sdk
Dswitch for the straight dart sdk.

Related

Homebrew: How do you specify a version using brew cask?

How do I specify a version number when installing something with brew cask install?
For recent versions of Homebrew, Jethro' instructions below may not work work, because we will get an error like:
Invalid usage: Non-checksummed download of <FORMULA_NAME> formula file from an arbitrary URL is unsupported.
I found a workaround:
Go to the Homebrew Cask search page: https://formulae.brew.sh/cask/
Type and find the application you are looking for
Click Cask code link
On Github click History button
Find the version you need by reading the commit messages and view the raw file. Confirm the version variable (normally on line 2) is the version you need.
Click on the name of the commit, then three dots and select View file
Right-click Raw button and Save Link As... to download the file locally
When downloaded, go to download directory cd Downloads/
Finally run brew install --cask <FORMULA_NAME>.rb
Voilà 😄
If you need some visual assistance check the screenshots here.
You can manually point brew at the ruby file for a specific version of a cask, using a git hash. This lets you control which version is installed.
For example:
Find the cask .rb file on the homebrew-cask git repo that you
want.
Get the commit hash, eg
cee7983cd95fc92fdc250fc509f2379cefe647fe in the example above.
Git may give you instructions to view the file history locally - eg git clone https://github.com/Homebrew/homebrew-cask.git git log master -- Casks/CASK_NAME.rb
Point brew at the file using the hash: brew cask install https://raw.githubusercontent.com/caskroom/homebrew-cask/cee7983cd95fc92fdc250fc509f2379cefe647fe/Casks/minikube.rb
The other answers are pretty heavy handed, an alternative is to use the homebrew/cask-versions tap which contains a list of the old (major) versions of casks.
To use them tap it with brew tap homebrew/cask-versions and then you can search for your cask again like brew search --cask yourformula and see if what you're looking for is there.
Or you can see the complete list of casks by clicking on Casks folder at https://github.com/Homebrew/homebrew-cask-versions .
If you run
brew edit [formula]
you can change the version that matches your operating system. If you know the checksum, enter that too. If not, just comment that line out with # and it will skip the check. Then run
HOMEBREW_NO_INSTALL_FROM_API=1 brew reinstall [formula]

Dart - getting start - missing step - how to install pub

I'm trying to get started and setup to develop Dart.
I'm following the instructions on https://webdev.dartlang.org/guides/get-started to install on Linux. However there seems to be an essential step missing.
On the above link, step 2 is about installing the SDK.
Step 3 is titled:
Get CLI tools or WebStorm (or both)
However step gives examples of using the pub command, and the links it references also use this command, however there are no instructions on where to find the pub utility or how to install it.
I would have assumed that pub was provided as part of the Dart SDK. I can run dart in my terminal, and see that it is installed. For example dart --version returns Dart VM version: 2.0.0 (Unknown timestamp) on "linux_x64". But pub returns zsh: command not found: pub
My question, therefore, is where do I find, and how do I install pub?
You need to add thedart-sdk/bin directory to the system PATH variable.

How can i change my dart-sdk on VSCode

i have been using flutter recently and i really wanted to use Jaguar for my project. But here is the catch, the flutter sdk brought dart with version 2.0.0-dev-58.0 but jaguar said they need dart sdk with version 2.0.0-dev-65.0
Okay, so i get myself dart with sdk version of 2.1.0-dev.1.0, but my vscode can't seem to recognize that i have installed the sdk.
Any ideas on how to change that?
The Dart Code plugin has a setting dart.sdkPath
The location of the Dart SDK to use for analyzing and executing code.
If blank, Dart Code will attempt to find it from the PATH environment
variable. When editing a Flutter project, the version of Dart included
in the Flutter SDK is used in preference.
There's also dart.sdkPaths which allows quick switching between alternatives.
For Flutter projects, use dart.flutterSdkPath(s)
It's quite easy if you use VSCode:
Clone flutter repo to a new folder:
mkdir ~/flutter_dev
cd ~/flutter_dev
git clone https://github.com/flutter/flutter.git .
Open your workspace preferences and update dart.flutterSdkPath setting:
"settings": {
"dart.flutterSdkPath": "/Users/youruser/flutter_dev"
}
Restart VSCode and you're good to go.
See more info in Dart Code - Quickly Switching Between SDK Versions
I want to add one more things to #Andrey, you can use FVM to install as much as you want versions and channels, it's easy to install and manage versions. It hold all versions on your home directory, I think it's easier than managing with Git.

Is it possible to get Homebrew to install from the latest commit on GitHub?

I need to use the LFTP program for a script I run. I tried installing it from the website using the instructions in the downloaded folder's "INSTALL" file, but running config always failed. So, I tried to have Homebrew install it, and that worked great.
I have no idea where Homebrew fetches its source from, but the latest version it pulled has a bug which the developer has since fixed on GitHub. Is there a way I can get Homebrew to install the source from the latest commit?
Some packages, such as numpy have a --HEAD option.
--HEAD
Install HEAD version
but the lftp package doesn't have this option. One solution could be to implement it yourserlf:
brew edit lftp
P.S. the homebrew version of lftp already include a patch:
https://raw.githubusercontent.com/macports/macports-ports/edf0ee1e2cf/devel/m4/files/secure_snprintf.patch
it's maybe the same you are looking for. You can see how it's apply whit brew edit lftp.

How to install a specific version of swiftlint?

I am trying to fix this error:
Error: swiftlint does not have a version "0.11.1" in the Cellar.
by running this:
brew install swiftlint-0.11.1
however this doesn't work, then I tried "brew search swiftlint", but nothing showed up.
Can anyone point to me the correct way to install swiftlint with a specific version?
Go to /usr/local/Cellar/swiftlint you will see all installed switflint version.
Copy swiftlint version folder from other Mac then paste into /usr/local/Cellar/swiftlint
You could check all versions in your Mac by brew info swiftlint
Switch to version you need by brew switch swiftlint x.xx.x
I uploaded some version ==> here
Update: Now you could use pods for this.
My project is using swift2.2 with SwiftLint 0.12.0 installed via brew.
And I decided to change to Pod. There are many changes and errors in each versions. My project is too big, and it's take time to fix all the error and warning (it may effect to current features also...).
Finally I choose pod 'SwiftLint', '0.16.0' and. disable_rules then I don't need to fix any warning nor error.
type_name
shorthand_operator
unused_closure_parameter
This involves a lot of steps, but anyway:
Find the Brew Formula for Swiftlint. It's here.
Now you'll need an older commit of Swift Lint, so you would normally click on the History tab and get to an older commit. However, GitHub might tell you that you need to clone the repo (git#github.com:Homebrew/homebrew-core.git) and then use git log master -- Formula/swiftlint.rb to find your older commit. I'll spare you the details of that.
Now you need a raw URL for an older commit. So the raw URL for the latest commit is https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/swiftlint.rb, but you would use https://github.com/Homebrew/homebrew-core/blob/COMMIT/Formula/swiftlint.rb
Now you can do a brew install directly using this older Swift Lint. In my case, I needed 0.15, so I used:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/864095ea97b6d7dc88c772c7f9f36521cf81a77e/Formula/swiftlint.rb
Just go to Swiftlint release page and select the appropriate version.
Download it and extract it.
You should be able to see an executable and a licence txt file.
Now go to /usr/local/Cellar/swiftlint and create a folder with the version (for ex. 0.35.0).
Create a bin folder inside it and paste the swiftlint executable that you have downloaded.
Brew now shows the custom version that you have downloaded . You can check by typing brew info swiftlint in cmd
you can switch by brew switch swiftlint version_number
With mint, which I personally prefer, you can do:
mint install realm/SwiftLint#0.46.2
Go to the SwiftLint's releases section and find the version you're looking for.
Then download its installer (.pkg, .zip, etc), and run it.

Resources