ChatGPT解决这个技术问题 Extra ChatGPT

How do I change the version of yarn used?

I used Homebrew to install yarn. Running yarn -v shows that I currently use 0.23.2. I ran brew upgrade yarn to get the latest version, which is 0.24.6.

After Homebrew successfully upgrades yarn, I run yarn -v again, but the version is still 0.23.2. How can I change the version of `yarn that I am running?

what's ur terminal output of which yarn?
/Users/DavidHu/.nvm/versions/node/v6.2.1/bin/yarn
What is the output of this command: `ls -la /usr/local/bin/yarn``
you're hitting certain caching issues (/Users/DavidHu/.nvm/versions/node/v6.2.1/bin/yarn takes precedence over your /usr/local/bin/yarn). I would suggest you to go consistent with your package manager(for eg. OS level use homebrew, node packages use npm etc)
Hope this channel can help you github.com/yarnpkg/yarn/issues/1139

C
Christian Rauh
yarn policies set-version <version number>

Per https://github.com/yarnpkg/yarn/issues/7146#issuecomment-477809216


This should be the correct answer but one thing to note, if you downgrade the yarn command policies may not be available in that version of yarn.
Is this method still correct? $ yarn policies set-version 1.19.1 yarn run v1.3.2 error Couldn't find a package.json file in "[deleted]" info Visit yarnpkg.com/en/docs/cli/run for documentation about this command.
Worked for me downgraded to 1.16.0 from 1.21.1
In yarn 2 it’s yarn set version <version number> as per next.yarnpkg.com/cli/set/version
If you use this command and try to download a later version of node it'll revert back to the version you used in this command even if you remove ~/.yarn and reinstall so beware of that
m
mycargus

You can use homebrew and yarn formula URLs to install older versions of yarn, then brew switch between yarn versions as needed. Works perfectly! Credit to github user robertmorgan.

First off, if you already have a version installed, unlink it from brew running the brew unlink yarn command in your terminal. Next, in a web browser, find the Pull Request that has been merged which contained the formula (version) of Yarn that you want to install. View the files changed in that Pull Request - there should be one for Formula/yarn.rb. Click the "View" button for the Formula/yarn.rb file to see the whole contents of the file for that commit. Click the button to view the "Raw" version of that file. This will open a url which should start with https://raw.githubusercontent.com/.... This is the URL that you will need for the next step - so copy the complete URL to your clipboard. Back in your terminal window, use the command brew install followed by the URL that you've copied. e.g. to install v1.6.0 of yarn it would be: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/fba7635ab69384ac980c635483a7af825bc06088/Formula/yarn.rb You can then verify the versions available to Homebrew by running: brew list --versions yarn, and switch between versions using brew switch yarn VERSION_NUMBER

Source: https://github.com/yarnpkg/yarn/issues/1882#issuecomment-421372892


im not sure how things went but 2018, this should be marked as the correct answer :)
As of 2021, installation of yarn from a GitHub commit URL is unsupported. I instead had joy with brew extract --version <version> yarn homebrew/cask and brew install yarn@<version>
I tried to do this, brew install https://raw.githubusercontent.com/DanBuild/homebrew-core/552359058976923c627d00e3dc99b40746618c7f/Formula/yarn.rb and got this error: Invalid usage: Installation of yarn from a GitHub commit URL is unsupported! brew extract yarn to a stable tap on GitHub instead. (UsageError)
Christian has the correct answer - Here is what I did:
Christian has the correct answer - Here is what I did: brew extract --version 1.6.0 yarn homebrew/cask and then brew install yarn@1.6.0
d
davidhu

I found an answer. It's not the prettiest, but since yarn always tell me what the most update-to-date version is, I can use npm to just install the latest version.

If the latest is 0.24.6

npm install --global yarn@.24.6

EDIT:

According to yarn's official documentation, the way to install/upgrade is:

brew install yarn

brew upgrade yarn

https://yarnpkg.com/en/docs/install#mac-stable


Yarn's official stance on npm is "don't." Quote: "Note: Installation of Yarn via npm is generally not recommended. When installing Yarn with Node-based package managers, the package is not signed, and the only integrity check performed is a basic SHA1 hash, which is a security risk when installing system-wide apps. For these reasons, it is highly recommended that you install Yarn through the installation method best suited to your operating system."
@jelder Does yarn provides any reasonable/straight-forward documented fix for this issue?
if you have denied with any write permission try this 'sudo npm install --global yarn@.24.6' it will ask your system password and enter
C
Community

Your best bet would be to use a yarn version manager.

Install:

curl -fsSL https://raw.githubusercontent.com/tophat/yvm/master/scripts/install.sh | bash

Single usage:

yvm exec <version> <command>

Or to switch your currently running yarn version

yvm use <version>
yarn --version

Getting -bash: yvm: command not found after running install and opening new terminal. Any ideas?
@TaylorAustin source ~/.yvm/yvm.sh does the job
t
talabes

UPDATE Dec 2021:

Sadly brew switch is deprecated in Homebrew 2.6.0 (December 2020)

$ brew switch
Error: Unknown command: switch

TLDR, to switch version:

brew unlink yarn
brew link yarn@<new_version>

Old solution:

Assuming that you have the other version installed, you can run

brew switch yarn <old_version>

To list the versions you have installed:

brew list --versions yarn

C
CrazyVideoGamer

You can use

yarn set version <version>

For example, if you want the latest version, you can run

yarn set version latest

You can also set it to a specific number, for example,

yarn set version 1.22.1

You can view the full documentation at the official website.

Note 1: A bug stops you from switching from yarn 2 to yarn 1. There are solutions to this in this GitHub issue.

Note 2: I don't use brew, but this solution should still work.


It's still works.
d
daddeo

Easily install and switch between any number of yarn versions.

https://github.com/tophat/yvm


R
Razzi Abuissa

Here's a way to do it with only curl and bash:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.24.6  # or another version

This works whether you have yarn installed or not.


A
AmerllicA

For updating version on macOS use below command:

$ brew upgrade yarn

c
cheesydoritosandkale

Some of the above answers don't seem to work anymore. Here is how I was able to install a different version in April 2021:

brew unlink yarn@1.6.0 (If you already have a version installed)

brew extract --version 1.22.4 yarn homebrew/cask

brew install yarn@1.22.4

yarn -v