Yarn: Document how to install yarn when you use nvm

Created on 26 Apr 2017  Â·  27Comments  Â·  Source: yarnpkg/yarn

I have a mess here on my both machines, running on Ubuntu and Mac OS. Both have the same problem: how to install yarn properly when you use nvm?

nvm, as you know, is an isolated nodejs manager. But when you do brew install yarn or sudo apt-get install yarn, then a system-wide nodejs version is installed (as a dependency)

This nodejs dependency is breaking a lot on my machines. This isn't working well. Ideally it would be good if we still can install and upgrade yarn through npm; or at least make brew + apt-get smarter, not installing the nodejs dependency when nvm already exist.

Looking at older issues, I see this has been discussed but there are too many comments to process. Can we agree to an official solution to the above and document this on the installation page?

cat-documentation triaged

Most helpful comment

Just an update for anyone who comes across this issue via Google search...Yarn documentation now says that Yarn can be installed on a Mac, via Homebrew, without node, like this:

brew install yarn --without-node

All 27 comments

On Debian-based distros (including Ubuntu), you install Yarn this way to avoid installing a Node.js package:

apt-get install --no-install-recommends yarn

Homebrew has a similar flag, but I can't remember it off the top of my head.

The install script will also work:

curl -o- -L https://yarnpkg.com/install.sh | bash

@bestander triage; label: [documentation] (which doesn't seem to be an existing label... perhaps worth making?)

now we have :)

thanks for that - yeah, please document.

and curl -o- -L https://yarnpkg.com/install.sh | bash is not an option for me because it does not get automatically updates like apt-get and brew do.

This is a community project, we hope that people who need this would step in and help each other, e.g. send a PR for documentation.

alright, i ll do a PR next week. can you confirm the curl command installs only but doesn't update?

That script should update

Quoting @Daniel15 https://github.com/yarnpkg/yarn/issues/3255#issuecomment-297908242:
_"...Homebrew has a similar flag, but I can't remember it off the top of my head."_

I don't see that option in the formula: https://github.com/Homebrew/homebrew-core/blob/master/Formula/yarn.rb, I've opened https://github.com/Homebrew/homebrew-core/issues/14026 for this to be added to the Yarn Homebrew package.

I think there's an --ignore-dependencies flag

Sent from my phone.

@Daniel15

apt-get install --no-install-recommends yarn
Thanks. It works!
And what about next time I run sudo apt upgrade ? Will new version of yarn install nodejs?

Just an update for anyone who comes across this issue via Google search...Yarn documentation now says that Yarn can be installed on a Mac, via Homebrew, without node, like this:

brew install yarn --without-node

@andrewhavens your note timestamp is right on time. TY

@app

@Daniel15

apt-get install --no-install-recommends yarn
Thanks. It works!
And what about next time I run sudo apt upgrade ? Will new version of yarn install nodejs?

Was there an answer to this? If I apt-get install --no-install-recommends yarn will nodejs be installed when I upgrade or not?

Sorry I didn't answer that! It shouldn't - AFAIK Debian only looks at "recommended" packages on initial installation, not on upgrades.

What about installing on CentOS/Fedora using nvm?
Yes, this is something that I actually need to do.

yum says the following…

===========================================================================================================================================================================
 Package                                Arch                                   Version                                          Repository                            Size
===========================================================================================================================================================================
Installing:
 yarn                                   noarch                                 1.6.0-1                                          yarn                                 916 k
Installing for dependencies:
 libuv                                  x86_64                                 1:0.10.34-1.el6                                  epel                                  57 k
 nodejs                                 x86_64                                 0.10.48-3.el6                                    epel                                 2.1 M

Transaction Summary
===========================================================================================================================================================================
Install       3 Package(s)

Total download size: 3.0 M
Installed size: 11 M
Is this ok [y/N]:

I presume I want to install yarn and libuv but not nodejs. Correct?

--- edit ---

Actually, it looks like libuv is a dependency of node so it should already be managed by nvm — so I just want yarn itself and none of the dependencies?

Maybe I'm missing the obvious. There is presumably no harm in having the node package installed when I am using nvm. Right? That means I don't actually have to skip installing the dependencies (which can't be done via yum without first modifying the package).

Anyone know how to do this on Solus?

sudo eopkg install yarn --ignore-dependency

@binarykitchen can you add @andrewhavens comment to your initial comment as an edit? it would be very helpful to have that at the top of the page for people who come here from google.

brew install yarn --without-node

still wants to install node:

$> brew install yarn --without-node
==> Installing dependencies for yarn: python, sphinx-doc, python@2, icu4c and node

I guess it is because of this commit https://github.com/Homebrew/homebrew-core/commit/a34c721586fece6d36d9b60fec5760e1b3361f11 but I'm not 100% sure as I have little knowledge of Homebrew.

Following @andrewhavens comment in the thread, another update for anyone who comes across this issue via Google search.

Yarn documentation currently says to install using brew install yarn and mentions that it'll pull in the node dependency (and transitively pull python2, icu4c).

Point being, homebrew devs are essentially saying that you must install node from homebrew because homebrew doesn't support installation options anymore (warning long thread, lots of heated discussion). And because yarn cannot work without node, obviously, they will install a system wide node for you.

If you still don't want to install node from homebrew simply do brew install yarn --ignore-dependencies. Make sure your $PATH is sorted properly as mentioned in the docs.

if anyone else comes across this issue from google and has the following setup like me: node installed from nvm, path correctly updated to include nvm's binary path but brew will still refuse to use that node version, you can try the following:

you can use brew edit yarn to temporarily comment out the depends_on "node" line and yarn will be installed without the node dependency. worked great for me. again, make sure that you have a node version present in your $PATH

@alexraileanu brew install --ignore-dependencies yarn does exactly that (yours is a precise way of excluding the node as dependency), but you'll have brew complaining next time yarn formula gets updated.

@wadkar yeah tho in my case, for whatever reason, brew would not find the node binary in my path so when i ran with --ignore-dependencies it would try to execute node from /usr/local which i didn't have. which is why i had to comment that requirement out.

thanks @alexraileanu
the only solution that worked for me in macOS Catalina.

Was this page helpful?
0 / 5 - 0 ratings