Why doesn't yarn updated when running upgrade? - macos

I'm trying to use latest yarn version after upgrading it.
I've follow over https://yarnpkg.com/en/docs/install#mac-stable instructions, but yarn didn't really upgraded.
After running brew upgrade yarn:
$ brew upgrade yarn
Updating Homebrew...
Error: yarn 1.9.4 already installed
And after running yarn --version:
$ yarn --version
1.9.2
Is there any way to use the latest version?
Although the guide says that brew upgrade yarn should do it automatically..

There's a lengthy thread on Github regarding upgrades; here's what is suggested for HomeBrew:
brew upgrade yarn
brew link --overwrite yarn
Then try yarn -v
If that fails then you could:
First, uninstall brew's yarn:
brew uninstall yarn
Removing yarn binaries manually:
rm -f /usr/local/bin/yarnpkg
rm -f /usr/local/bin/yarn
Remove yarn cache:
rm -rf ${HOME}/.yarn
If you have the following in your .zshrc or .bash_profile, remove it:
export PATH="$PATH:`yarn global bin`"
Install via curl:
curl -o- -L https://yarnpkg.com/install.sh | bash
Make sure there is the following line in your .zshrc or .bash_profile:
export PATH="$HOME/.yarn/bin:$PATH"
↳ Github : yarn update discussion thread

If you installed yarn with npm in an nvm environment then you can just run npm -g upgrade yarn. To check that run which yarn -- if you see .nvm in the result of that, you are in an nvm environment.

Related

Command not found: corepack when installing Yarn on Node v17.0.1

I'm following the Yarn installation instructions on Yarn's website (https://yarnpkg.com/getting-started/install). Those instructions say that on Node version 16.10.0 and higher you can install Yarn by enabling corepack with the following command:
corepack enable
However, running that command returns:
zsh: command not found: corepack
I installed Node via Homebrew and node -v returns v17.0.1. I'm on an M1 Mac running Big Sur.
Because I had installed node via nvm (and I had installed nvm using Homebrew), the corepack command wasn't available. The fix that worked for me was to install corepack via homebrew by running:
brew install corepack
After installing corepack via homebrew, I was able to run the corepack enable command from the terminal and the yarn command became available as well.
Was facing a similar issue with node installed using asdf. Also using zsh and zsh asdf plugin.
Node version: 16.13.1
Ran corepack enable - and got
zsh: command not found: yarn
What solved for me:
asdf reshim nodejs
Also try to run
corepack prepare yarn#3.1.1 --activate
before reshim
I solved it like this:
From the https://github.com/nodejs/corepack docs
npm uninstall -g yarn pnpm
npm install -g corepack
Use with 'sudo' if you're using OSX

terminal defaults to old yarn version (lerna bootstrap)

I don't think this is an issue specific to lerna, I actually think it is nvm related (though I commented out nvm from my .bash_profile to test that, without success).
I'm trying to lerna bootstrap but it keeps using (and failing) an older version (1.3.2) of yarn than what I'm running:
$ yarn -v
1.22.4
$ lerna bootstrap
info cli using local version of lerna
lerna notice cli v3.22.1
lerna info versioning independent
lerna info bootstrap root only
yarn install v1.3.2
error An unexpected error occurred: "patterns.map is not a function".
info If you think this is a bug, please open a bug report with the information provided in "yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in 'root'
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in 'root'
$ yarn -v
1.22.4
For me, this was happening in Ubuntu 20.04, and it solved with unistalling cmdtest:
sudo apt-get purge cmdtest
I rooted around in my filesystem and removed ~/.yarn and ~/node_modules/yarn and everything works now.
Upgrade yarn. I use brew so I used brew install yarn and it worked.

How do I change the version of yarn used by my system?

I am running Mac OS X 10.14.6 and I am trying to get the latest version of yarn installed and working on my system.
So I installed it with Homebrew, it tells me that I already have it installed on my system:
$ brew install yarn
Warning: yarn 1.21.1 is already installed and up-to-date
But when I do yarn --version, I get this:
$ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
So I try to reinstall it and the following happens:
To reinstall 1.21.1, run `brew reinstall yarn`
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Transmit-Live $ brew reinstall yarn
==> Reinstalling yarn
==> Downloading https://yarnpkg.com/downloads/1.21.1/yarn-v1.21.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/downloads/784c559ca8d97--yarn-v1.21.1.tar.gz
🍺 /usr/local/Cellar/yarn/1.21.1: 14 files, 5MB, built in 8 seconds
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
I have also tried brew switch and that doesn't work:
$ brew switch yarn 1.21.1
Cleaning /usr/local/Cellar/yarn/1.21.1
2 links created for /usr/local/Cellar/yarn/1.21.1
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Edit 1
I even tried to do brew upgrade yarn and it is the same issue:
$ brew upgrade yarn
Warning: yarn 1.21.1 already installed
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Edit 2
Output of which yarn:
$ which yarn
/.rvm/gems/ruby-2.7.0#myapp/bin/yarn
How do I fix this?
Thanks.
I figured it out.
Basically what was happening is that I had two versions of yarn installed. One was a gem, and the other was the yarn executable.
So I simply ran gem uninstall yarn and it fixed it.
$ gem uninstall yarn
Remove executables:
yarn
in addition to the gem? [Yn] Y
Removing yarn
Successfully uninstalled yarn-0.1.1
Now when I do yarn --version it works properly.
$ yarn --version
1.21.1
You can upgrade a package with brew upgrade, so something like
brew upgrade yarn
You may need to get homebrew to update it's package list first, with brew update
[Edit]
In your case there is some confusion, the yarn package that brew installs is the javascript package manager, whereas the yarn you have on your path is the ruby gem. You can upgrade the latter with gem update yarn. If you want to use the JavaScript package manager, try modifying your path, or use the fully qualified path (something like /use/local/bin/yarn)

How do I upgrade yarn to a specific version

The Yarn documentation tells us how to upgrade to the latest version, but does not explain how to upgrade to a specific non-latest version.
I need a specific version to match our CI server.
How do I specify the version that I want?
run yarn policies set-version <version> from the project directory
https://classic.yarnpkg.com/en/docs/cli/policies/#toc-policies-set-version
As you can see in the documentation, you can provide a version to the curl-install command with the --version flag.
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
In case you are using brew:
brew switch yarn [version]
Or maybe you installed it with npm as global package, then update like that:
npm install --global yarn#[version]
yarn set version [version.number] should work.
You can specify the yarn version using install in the following way:
Assuming you want version 1.7.0:
yarn upgrade v1.7.0
On Mac OSX 12.2.1 had following message when tried yarn upgrade v1.22.17
warning Your current version of Yarn is out of date. The latest version is "1.22.17", while you're on "1.22.4".
info To upgrade, run the following command:
$ brew upgrade yarn
success Saved 0 new dependencies.
So just did brew upgrade yarn and yarn --version returned 1.22.17

PhoneGap Mac CLI local install failed because of Node version

So I want to debug my Phonegap webapp locally in Xcode.
I follow the step here and here, and launch in MAC CLI
$ sudo npm install -g phonegap
BUT install failed and CLI result get lots of errors with the first one is :
engine phonegap#2.9.0rc1-0.12.0: wanted: {"node":">=0.10.0"} (current: {"node":"v0.8.8","npm":"1.1.59"})
I understand my node version is too old : 0.8.8
node --version
I try to update but I am stuck with those 2 methods here and both in errors for me :
BREW
Tried Homebrew but did not work :
$ brew upgrade node
Error: node-0.8.8 already installed
NPM
As I found here
Upgrading Node.js to latest version
How do I update Node.js?
$ sudo npm install -g n
$ sudo n stable
sudo: n: command not found
In fact my bash_profile was missing the path to the n module as I found here:
cannot install npm? problems generating application
Edit your ~/.bash_profile. Add this export somewhere.
export PATH=/usr/local/bin:$PATH:/usr/local/share/npm/bin
I had the same issue and fixed it by upgrading node with brew, I just run
brew install --upgrade node

Resources