Pida
Pida

Reputation: 988

Can't install Ember Octane on Mac; problems with NPM and NVM

I'd like to install the most recent version of Ember on my Mac with MacOS Catalina. I actually thought I had done so a few weeks ago (this machine is only three months old), but ember -v says that Ember CLI is at version 3.9 which is 13 months old.

So I entered npm install -g ember-cli in the terminal, but I get an error:

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user

So I did what is suggested here and tried to install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

There's some output and everything is looking finde, but when I try to verify my installation using command -v nvm, there's no output at all.

npm uninstall ember-cli gives me up to date in 0.031s.

What can I do to get Ember Octane running?

edit: I managed to install NVM using Homebrew. nvm -v says 0.35.3. But I don't find any information on how to continue from here. I still get the same error when trying to install Ember.

Upvotes: 0

Views: 306

Answers (1)

Lux
Lux

Reputation: 18240

Your problem lies in your comment:

npm bin says /Users/<my-username>/node_modules/.bin. which ember says /usr/local/bin/ember. Now it is important to understand the PATH.

Your PATH includes multiple directories and whenever you enter a commend it will be looked up in all theese directories. Now your PATH definitly contains /usr/local/bin/ and maybe later /Users/<my-username>/node_modules/.bin. It definitly should contain borth directories. If it does not contain /Users/<my-username>/node_modules/.bin thats something you should fix immediatly.

Now however your primary problem is that you basically installed ember-cli twice in two versions with two versions of npm. At the time you've installed ember originally you didnt use nvm yet. And using npm with nvm is in some ways significantly different from using it without it.

If you're using nvm basically everything lives in your $HOME (so /Users/<username>). Also the folder where npm install -g will install binaries into, it will be /Users/<my-username>/node_modules/.bin. This is actually a good thing because this means every user can install its own things there without sudo. On the other hand if you use the global npm you will install binaries installed with npm install -g into /usr/local/bin/. This however either requires sudo or changing some permissions. We dont know what you did back then, maybe you tried it once with sudo, and since then this one version basically overwrites all other versions you may install later with nvm because /usr/local/bin/ comes in your PATH before /Users/<my-username>/node_modules/.bin.

Now what you should do is get rid of /usr/local/bin/ember first. For this you do ls -lisa /usr/local/bin/ember because this is probably a symbolic link to somewhere else. Then you check where this link leads to and remove ember-cli from there. It is probably safe to just rm -rf the packages installed there. Next you delete the symbolic link /usr/local/bin/ember itself. Then run which ember again. Not this should either either fail or point to a different path. If it points to a different path you can verify that it is the version you want (in /Users/<my-username>/node_modules/.bin). If it fails you should verify that /Users/<my-username>/node_modules/.bin is actually in your PATH and that ember exists in /Users/<my-username>/node_modules/.bin.


Besides that I want to mention that ember-cli also has some interesting detail: if you run ember-cli inside an ember project it will search for the ember-cli installed inside this project and start it. So the global installed ember-cli version actually doesnt matter that much. It is basically only relevant for ember new. However for ember new you maybe want to consider to use npx because then you will always run the current version. So you could do npx ember-cli new my-app.

Upvotes: 4

Related Questions