Deploy the Node.js environment on the Mac environment and install the Angular CLI to solve the problem that the ng command cannot be found
February 08, 2018 23:34:56
Number of readings: 207
The reason for writing this blog is that I recently learned that the AngularJS
company environment is Ubuntu and the home environment is macOS
. The company built the Angular environment very smoothly, and it ended up on the Mac...
So I decided to record it, hoping to help more people.
To install Angular CLI, you need to install the Node.js environment first
. There are three ways to install Node.js on Mac:
1. Install through third-party Homebrew
2. Install through git
3. Download the installation package from the official website for installation
This blog uses the third method above
- Node.js official website download stable version installation package
- Currently I am using 8.9.4 with npm version 5.6.0
- Double-click to install, enter the user password, no more details
- Open the terminal and enter to
node -v
view the node version Enter tonpm -v
view the npm version - To install the Angular CLI, just run the following command in the terminal:
npm install -g @angular/cli
- At this time, if the input
ng v
can display the pattern and prompt of Angular CLI, as shown in the figure below, the installation is successful.
But unfortunately I am prompted when I use the ng commandng: command not found
After some data review, I got the following solution:
The process is to delete all node and npm first, then reinstall it, and finally reconfigure it.
- remove node and npm
npm config get prefix
cd [刚才得到的路径]
cd lib && rm -rf node_modules
cd /usr/local/lib && sudo rm -rf node*
cd /usr/local/include & sudo rm -rf node*
brew uninstall node (如果你是通过brew安装的,才需要执行此步骤)
cd /usr/local/bin
sudo rm -rf npm
sudo rm -rf node
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
- Reinstall Node.js
- install @angular/cli
npm install -g @angular/cli@latest
- Query the installed Node path
npm get prefix
- Assign the path just now to your terminal configuration file .zshrc or .bashrc
alias ng="/刚才你得到的路径/lib/node_modules/@angular/cli/bin/ng"
- At this point, the ng command is already easy to use