2

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

echo $PATH

14
  • 1
    What does typing npm list -g --depth=0 say Commented Jan 6, 2018 at 19:04
  • I tried that before and it says that @angular/[email protected] is in the following path: /Users/<user name>/.npm-global/lib Commented Jan 6, 2018 at 19:16
  • 1
    that doesn't sound like a mac. Commented Jan 6, 2018 at 19:19
  • Are you running a virtual machine? Commented Jan 6, 2018 at 19:21
  • 1
    Try following 3 things,1. npm uninstall -g @angular/cli 2. npm cache verify 3. npm install -g @angular/cli@latest (uninstall, clean npm cache, reinstall) Commented Jan 6, 2018 at 19:44

6 Answers 6

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

What if you are running into this error on windows, while being admin ?
1

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:

  1. Use a Version manager (like Node Version Manager)
  2. Change nodejs default installation directory

Comments

1

Nodejs website installation package installed it almost like it expected a pc. So we're seeing two issues here

  • Premission on directory it was installed, which can be fixed with chmod
  • Location unknown, which can be fixed with 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 

Comments

1

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)

Comments

0

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:

  1. Delete any existing NPM packages:

    sudo rm -rf /usr/local/lib/node_modules

  2. Delete your current installation of Node and NPM:

    brew uninstall node

  3. Preconfigure NPM to install packages in a location under your home directory:

    echo prefix=~/.npm-packages >> ~/.npmrc

  4. Add the new NPM packages location to your shell's search path:

    echo 'export PATH="$HOME/.npm-packages/bin:$PATH"' >> ~/.bash_profile

  5. Quit and re-launch the Terminal app

  6. 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.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.