简体   繁体   中英

bash ng command not found mac

bash ng command not found mac ng serve works for me only the time when I just installed

ng serve works for me only the time when I just installed, after that I opened new terminal and after navigating to the angular project directory and try to run ' ng serve ' at that time the terminal is showing 'bash ng command not found'

Works well for me 1. Link cli to npm: npm link @angular/cli

  1. Set the location of npm folder: export PATH="$HOME/.npm-global/bin:$PATH"

  2. Clear cache and re-install cli: npm uninstall -g @angular/cli npm cache clean npm install -g @angular/cli

  3. Give alias to ng path : alias ng="/Users/Dharshini/.npm-global/lib/node_modules/@angular/cli/bin/ng"

  4. Go back to the base user: cd ~

  5. Change path using vim: sudo vim /etc/paths

  6. Add ~/.npm-global/bin to the end of the file. type i to insert type :wq to save and exit

  7. restart terminal and type: echo $PATH

  8. Finally know the version using: ng version

My solution: Node modules resides in the directory /opt/node/bin

Add these two lines to your .bashrc file NODE_BIN="/opt/node/bin" export PATH="$PATH:$NODE_BIN"

Save and close .bashrc and run: source .bashrc

.... Currently, both node and npm runs without being referenced in .bashrc, but that is because the executable files for node and npm are located in /usr/local/bin directory which itself is by default on the $PATH. So, instead of adding the 'ng' executable to /usr/local/bin, I exported /opt/node/bin to my path instead, to prevent any other modules in the future from not being found.

For solving this issue

-bash: ng: command not found

you need to set PATH, follow these steps and you'll be good to go:

  1. Set the location for npm Folder, Run any one of them:
 export PATH="$HOME/.npm-global/bin:$PATH" export PATH="$HOME/.npm-packages/bin:$PATH"
  1. Clear cache and Re-install Angular
 npm uninstall -g @angular/cli npm cache clean npm install -g @angular/cli
  1. Give an alias to ng Path-

    PATH = /Users/Dharshini/.npm-global/lib/node_modules/@angular/cli/bin/ng

 alias ng="PATH"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM