The following records the steps to install Node.js in the virtual machine (Homestaead) built with vagrant in the local Windwos environment and the production environment Alibaba Cloud CentOS system, as well as the differences in npm installation dependencies.
Install node.js using source code compilation. First uninstall Node.js on the machine, and I directly paste the steps provided on Stack Overflow:
1. Uninstall npm and Node.js
First uninstall npm, the command is: sudo npm uninstall npm -g , and then uninstall Node.js.
Running which node will return something like /path/bin/node.
Then run cd /path
This is all that is added by Node.JS.
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
If it is an Ubuntu system and is installed using apt-get, you can use the command:
sudo apt-get remove nodejs
2. Download, compile and install Node.js
Node.js official download page: https://nodejs.org/en/download/current/
I chose the latest version, the download address is: https://nodejs.org/dist/v6.3.1/node-v6.3.1.tar.gz
Generally, the installation directory of third-party software on Linux is /usr/local. Use wget to download the source code (replace the address yourself):
sudo wget http://nodejs.org/dist/v0.10.30/node-v0.10.30.tar.gz
Decompress:
tar xzvf node-v* && cd node-v*
Compilation:
./configuremake
This process can be slow, wait for completion and then install:
sudo make install
If everything goes well, Node.js is installed and use node -v to view the version.
vagrant@homestead:/usr/local$ node -vv6.3.1
3. Install npm dependencies
Here, the virtual machines on Windows are different from real Linux systems. Directly on Linux:
npm install
However, the commands of Windows virtual machines need to be added with parameters, otherwise an error will be reported:
npm install --no-bin-links
4. Install Taobao npm mirror acceleration
In fact, before the third step, you can install Taobao's npm image first and use the command:
npm install -g cnpm --registry=https://registry.npm.taobao.org
In this way, most npm commands can be replaced by cnpm, such as:
cnpm install
Since I use Laravel's PHP framework, I need to use the gulp front-end build tool, so to install gulp, use Taobao npm mirror to install:
cnpm install --global gulp
At this point, the Node.js and npm dependencies were installed successfully, and everything was as new.
There is another method: don’t install cnpm and just use Taobao mirrors to set up npm’s mirrors:
npm config set registry https://registry.npm.taobao.org
Summarize
The above is the entire content of the process of uninstalling and installing Node.js and npm. I hope the content of this article will be helpful to everyone. If you have any questions, please leave a message to discuss.