Yarn: NPM refusing to install yarn globally

Created on 1 Mar 2017  路  16Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Bug Report

What is the current behavior?

When trying to install the latest version of YARN via NPM with the global flag the install fails with the error:

npm ERR! Refusing to delete /usr/local/bin/yarn: node_modules/npm/bin/npm-cli.js symlink target is not controlled by npm /usr/local
npm ERR! File exists: /usr/local/bin/yarn
npm ERR! Move it away, and try again.

I can install yarn locally without the global flag

If the current behavior is a bug, please provide the steps to reproduce.

  • Run npm i -g yarn

What is the expected behavior?

YARN should install globally

Please mention your node.js, yarn and operating system version.

I am using Docker on MacOSX with the official node image found here https://hub.docker.com/_/node/

NPM: 4.1.2
Node: 7.7.0
YARN: 0.21.3

I appreciate this maybe the domain of NPM / Node but I haven't encountered any issues installing other packages globally.

Thanks

Most helpful comment

@dylanrhysscott I found why: the latest docker image already has yarn installed globally. checkout the Dockerfile

All 16 comments

Here is the full log file

npm-debug.log.txt

This just started happening to us as well today.

@devinus Hi @bestander just read through #2744 and saw your comment to ping you in related issues. Could this be a unintended result of the changes made in the latest release? Looking at the error its related to symlinks and I know the above issue made some changes there.

What's weird is I was using yarn 0.21.3 just earlier last night perfectly fine. Something changed within the past ~6 hours it seems.

Can you install earlier versions of yarn?
Did npm get updated?

@dylanrhysscott I found why: the latest docker image already has yarn installed globally. checkout the Dockerfile

The Docker image already has Yarn installed globally. If you want to install your own version, please use the Debian or Alpine Linux package rather than npm, as that will work properly.

@fishead @Daniel15 Thanks for letting me know about this - I have a question though if yarn is already installed shouldn't NPM either do nothing / upgrade if there is a version available? Thats what happens with other NPM packages why not YARN?

It's not installed via npm. The Node.js Docker images install Yarn by using the standalone .js file we provide.

@Daniel15 OK so if the install is done outside of NPM then NPM can't manage it. Is that standard behaviour with all npm packages or something yarn specific?

Not standard with all npm packages, but pretty common for system-wide apps. Most of the time, you'll want to manage system-wide apps using a native package manager, particularly on Linux (like apt-get on Debian/Ubuntu or yum on CentOS) rather than npm. Some of the rationale for not using npm to install Yarn is documented on https://yarnpkg.com/en/docs/install#alternatives-tab:

Note: Installation via npm is generally not recommended. npm is non-deterministic, packages are not signed, and npm does not perform any integrity checks other than 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.

The strong point of Yarn / npm is to manage per-project dependencies, rather than system-wide dependencies. System-wide package management is better handled by the native package manager, which is also significantly more secure than npm.

@Daniel15 Thanks for the info that clears everything up! 馃憤

@fishead @Daniel15 is this also for node6-slim images? We've encountered the same issue (yarn refuses to be installed) on that image.

EDIT: Nevermind, I found this on the docker-node repo:

The node images come in many flavors, each designed for a specific use case. All of the images contain pre-installed versions of node, npm, and yarn.

In case you need to force the installation of the newest version you can:

  • Delete the symlink target rm /usr/local/bin/yarn
  • Run npm install -g yarn

In case you need to force the installation of the newest version you can:

  • Delete the symlink target rm /usr/local/bin/yarn
  • Run npm install -g yarn

Also remove this: rm /usr/local/bin/yarnpkg

Thank you all .. that was really helpful and solved an issue i have been facing for more than 6 hours. AWESOME folks really.

Was this page helpful?
0 / 5 - 0 ratings