Reputation: 69
Specs:
MacOS 10.12.6
Node.js v8.9.4
NPM 5.6.0
I'm new to programming (and stackoverflow). I installed Angular using the following command in the terminal: npm install -g @angular/cli. I ran into an EACCESS error but this resolved it. Initially I was able to run the ng command. But after closing and reopening the terminal, the "ng: command not found" error happened. I removed Angular and reinstalled it. But that didn't help.
Screenshot of the "ng: command does not exist" error
Screenshot of npm list -g --depth=0
Errors in uninstalling Angular part 1
Errors in uninstalling Angular part 2
Upvotes: 2
Views: 16282
Reputation: 79
Follow these steps:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
export NVM_DIR="/Users/Enter-Your-own-username/.nvm"
The below command will load nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
Type the below commands:
nvm install stable
nvm install node
Check for the installed version of the node to verify the installation node version
If you have node installed already then go for the below step:
npm install -g @angular/cli
And in the same terminal session type the below command:
ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Create a new project with:
ng new angularProject
ng server angularProject
type:
localhost:4200
That should do the job.
Upvotes: 0
Reputation: 256
Have you tried to check your NODE_PATH
environment variable value ?
echo $NODE_PATH
If it's empty (and given your default location of installation in MacOS) try to set it into:
export NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node
To make it more permanent put it inside your ~/.bash_profile
, then restart your terminal (otherwise source ~/.bash_profile
)
Upvotes: 1
Reputation: 272
You need to install @angular/cli globally NOT locally. if you type:
npm install -g @angular/cli
in terminal and you will get the error: ng: command not found or different error, it's because you do not have access to the global directory of npm
The solution is: just use sudo
sudo npm install -g @angular/cli
Upvotes: 3
Reputation: 2190
If you're using an installation of Node and NPM based on Homebrew, your installation may not keep your globally installed packages in a predictable location (mine didn't).
These steps helped me ensure Angular CLI and other globally-installed packages land in a predictable location and now they work in my terminal.
Summary:
Delete any existing NPM packages:
sudo rm -rf /usr/local/lib/node_modules
Delete your current installation of Node and NPM:
brew uninstall node
Preconfigure NPM to install packages in a location under your home directory:
echo prefix=~/.npm-packages >> ~/.npmrc
Add the new NPM packages location to your shell's search path:
echo 'export PATH="$HOME/.npm-packages/bin:$PATH"' >> ~/.bash_profile
Quit and re-launch the Terminal app
Install Angular CLI in your fresh Node setup:
npm install -g @angular/cli
Now the ng
command should exist at ~/.npm-packages/bin/ng
and you should be able to run ng --version
successfully.
Upvotes: 0
Reputation: 5731
Nodejs website installation package installed it almost like it expected a pc. So we're seeing two issues here
chmod
export
You can export by editing ~/.bash_profile and adding
export PATH="[Enter your path here]:$PATH"
But if you're new to this, I highly recommend to resort to helping installing software like homebrew approach very friendly mac installing/update for terminal.
Will want to uninstall your current node if possible.
Then it's
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew doctor
export PATH="/usr/local/bin:$PATH"
brew install node
npm install -g @angular/cli@latest
Upvotes: 1
Reputation: 483
I would suggest you tried another way of installing nodejs, like using Node Version Manager. It is really easy to use and lets you run multiple version of nodejs and npm dependencies on the same machine.
As it is stated in npm documentation, EACCESS errors usually go away with the following strategies:
Upvotes: 1