How to install yarn locally without adding any dependencies

61 views Asked by At

Installing yarn using dnf will install several packages on my machine that i don't want.

$ sudo dnf install yarnpkg-1.22.19-5.fc37.noarch 
Last metadata expiration check: 1:08:38 ago on Sat 17 Feb 2024 09:01:36 PM PST.
Dependencies resolved.
==============================================================================================================================================================
 Package                                 Architecture                  Version                                           Repository                      Size
==============================================================================================================================================================
Installing:
 yarnpkg                                 noarch                        1.22.19-5.fc37                                    updates                        5.3 M
Installing dependencies:
 nodejs                                  x86_64                        1:18.18.2-1.fc37                                  updates                        2.2 M
 nodejs-libs                             x86_64                        1:18.18.2-1.fc37                                  updates                         14 M
Installing weak dependencies:
 nodejs-docs                             noarch                        1:18.18.2-1.fc37                                  updates                        7.7 M
 nodejs-full-i18n                        x86_64                        1:18.18.2-1.fc37                                  updates                        8.5 M
 nodejs-npm                              x86_64                        1:9.8.1-1.18.18.2.1.fc37                          updates                        2.3 M

Transaction Summary
==============================================================================================================================================================
Install  6 Packages

Total download size: 40 M
Installed size: 203 M
Is this ok [y/N]: 

For example I already have node and npm from nvm in my home directory ~/.nvm/versions/node/v16.13.0/bin/npm

2

There are 2 answers

0
mikrowdev On

You can install yarn directly via npm as described also in the official documentation

https://classic.yarnpkg.com/lang/en/docs/install

npm install --global yarn
0
Hamad Noor On

CentOS / Fedora / RHEL

On CentOS, Fedora and RHEL, you can install Yarn via RPM package repository.

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo

If you do not already have Node.js installed, you should also configure the NodeSource repository:

curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -

Then you can simply:

sudo yum install yarn
## OR ##
sudo dnf install yarn