5

I read that on OS X you can install Yarn either by

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

  2. brew install yarn

  3. npm i -g yarn

What functional difference is there between these three methods? Why would someone choose one over the others?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
RNdev
  • 953
  • 1
  • 8
  • 26

2 Answers2

1

when using brew to install packages, you install them system wide. that is, you cannot have more than one version for the same package, which is usually problematic. for this reason, many other technologies have spawn, such as docker, snap.

moreover, each package manager has its own lifecycle and packs original package in a different manner for ease of use, distribution and maintenance. for instance, npm container is based on the release of npm package itself.

usually, you should stick to the package manager of the same ecosystem that you are using. specifically to your case, it will be recommended to use npm to install and update your package (using package.json). which will give each of your project to pin and lock the desired yarn version that you like, without any affecting your system wide.

speaking of npm, you might wish to look at this answer

Mr.
  • 9,429
  • 13
  • 58
  • 82
-1
  1. curl downloads the installation script from yarnpkg.com, and installs yarn using that script
  2. brew is a package manager for MacOS. It's meant to make things easier for people when installing commands for the terminal. When you install with brew, the package get's put into /usr/local/bin instead of /usr/bin so I believe that this is kind of like a virtual environment, and yarn wouldn't be installed into the core of your machine. You'll have to install homebrew before you can use it, and you install it using curl. I believe that there is less risk when using homebrew because of the reasons that it is kind of like a virtual environment
  3. npm is a package manager for javascript, it's the same as yarn. It's meant for easy installation of javascript packages.

I use brew for all installs to the terminal, and npm for all installs of javascript packages.

Sam
  • 1,765
  • 11
  • 82
  • 176
  • Installing via npm is the recommended way to install yarn v1 according to their docs https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable – Punit Apr 22 '22 at 13:35