Installing Yarn globally in Toolbox

I can’t seem to figure out how to install Yarn globally in Toolbox.

Upon running npm install --global yarn

I get npm WARN checkPermissions Missing write access to /usr/local/lib followed by a bunch of access denied errors.

I tried to install Yarn locally but as a new developer I’m not sure whether that is a good practice or not. I also can’t figure out how to execute Yarn when installed locally.

Any solutions? Should I consider running a podman node image instead of Toolbox? I’m looking to run and develop and Express app.

Hi @hankhill ,
In Toolbox, try the command again but sudo npm install --global yarn, that should suffice.

I’ve been advised against using sudo for npm. Is this not true for Toolbox?

Well, in toolbox, your user namespace is root, so that is okay for that particular case. Otherwise, you would need to install it with layering and livefs enabled AFAICT. So the container approach seems to be more sensible to me, especially on Silverblue and CoreOS and IoT. You won’t need a password either, though you still get the familiar warning about “great responsibility” etc…

If you use dnf to install node, npm will try a path that requires sudo. I would, however, advise against sudo, and instead set the npm global directory to somewhere else. You can follow these steps: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Even better would be using a node manager like Volta which allows setting an exact node version and bypasses this problem completely by installing node as user. Search this forum for volta for more information.

what about installing nvm (no toolbox needed) and then yarn gobally:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm install node
npm install -g yarn

more info here:

Thanks guys. NVM seems to be the best solution in every way.

A tip: Nvm is fine, but it’s slow due to being a weird bash script that just grew out of proportion. Setting it up and sourcing it is also stranger than it should be. If you care about speed, I’d go for fnm (which has a very similar feature set as Nvm, but written in Rust) or Volta, which has a slightly different feature set (not so concerned with checking installed version when you cd into a directory, but installing tools is easier.)