To install the latest version of yarn4.x we need nodejs to be installed first and yarn1.x...
To install the latest version of yarn4.x we need nodejs to be installed first and yarn1.x version
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg - dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=21
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
NODE_MAJOR
can be changed depending on the version you need.
NODE_MAJOR=16
NODE_MAJOR=18
NODE_MAJOR=20
NODE_MAJOR=21
sudo apt-get update
sudo apt-get install nodejs -y
sudo apt-get purge nodejs
rm -r /etc/apt/sources.list.d/nodesource.list
rm -r /etc/apt/keyrings/nodesource.gpg
brew install node
brew uninstall node
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install --no-install-recommends yarn -y
We don’t want apt-get to install nodejs again as we already installed the latest version of nodejs from the above method, so we are specifying — no-install-recommends in apt-get to not install nodejs.
sudo apt-get purge yarn
rm -r /etc/apt/sources.list.d/yarn.list
rm -r /etc/apt/keyrings/nodesource.gpg
brew install yarn
brew uninstall yarn
After following the above methods we assume that yarn1.x binary is added to your path, if not run the following command to add it to your path
corepack enable
If corepack is not installed already use npm to install it globally
npm install -g corepack
Now we have to create a project directory and switch to that directory
mkdir yarn-project
cd yarn-project
Initialize the project to use the latest version of yarn
yarn init -2
If you want to update yarn to the latest version you need to run:
yarn set version stable
yarn install
Now yarn will be configured to use the most recent stable binary
Yarn will periodically gather anonymous telemetry to disable it run
yarn config set --home enableTelemetry 0