Author: @ Ryan – Miao this article as the original, reproduced please indicate the source: www.cnblogs.com/woshimrf/p/…
directory
1.1 installation NVM
Use Taobao Mirror
1.2 installation node
Install Taobao image
Installation of yarn
1. Environment installation
Operating system: Ubuntu 16.04.2 LTS
1.1 installation NVM
ryan@ryan- 900.X5L:~/temp$ curl https://raw.githubusercontent.com/creationix/nvm/v033.4./install.sh | bash
Copy the code
- Note
v0.33.4
is the latest version from creationix/nvm - After the installation is complete, close and restart Terminal, and enter
nvm
You can verify that it is installed - The default installation directory is ~/.nvm
Use Taobao Mirror
Domestic environment, using Taobao mirror. Configure environment variables, modify. Bashrc append
# taobao npm mirror
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
Copy the code
1.2 installation node
Install the latest Node
nvm install node
Copy the code
Or specify the node version
ryan@ryan- 900.X5L:~$ nvm install 6.114.
Copy the code
You can then check the current installed version of Node
ryan@ryan- 900.X5L:~$ nvm ls
iojs-v33.1.
-> v611.4.
v87.. 0
default -> node (-> v87.0).node -> stable (-> v87.. 0) (default)
stable -> 8.7 (-> v87.. 0) (default)
iojs -> iojs-v33. (-> iojs-v33.1.) (default)
lts/* -> lts/boron (-> v611.4.)
lts/argon -> v48.4.(- >N/A)
lts/boron -> v611.4.
Copy the code
You can see that the arrow points to V6.11.4, now switch back to the latest version:
ryan@ryan-900X5L:~$ nvm use 8.7.0
Copy the code
You can view the Node version at this point
ryan@ryan- 900.X5L:~$ node -v
v87.. 0
ryan@ryan- 900.X5L:~$ npm -v
5.42.
Copy the code
Install Taobao image
npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code
Note that the CNPM is installed under the current VERSION of NPM. Such as:
ryan@ryan- 900.X5L:~$ nvm use 6.114.
Now using node v611.4. (npm v310.10.)
ryan@ryan- 900.X5L:~$ node -v
v611.4.
ryan@ryan- 900.X5L:~$CNPM not found'cnpm'Command, you want to enter: command'cpm'From the package'cpm'(universe) command'npm'From the package'npm'(universe) command'cxpm'From the package'xpmutils'(universe) CNPM: The command Ryan was not found@ryan- 900.X5L:~$ nvm use 8.7. 0
Now using node v87.. 0 (npm v54.2.)
ryan@ryan- 900.X5L:~$ cnpm -v
cnpm@5.11. (/home/ryan/.nvm/versions/node/v87.. 0/lib/node_modules/cnpm/lib/parse_argv.js)
npm@5.51. (/home/ryan/.nvm/versions/node/v87.. 0/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@8.7. 0 (/home/ryan/.nvm/versions/node/v87.. 0/bin/node)
npminstall@3.14. (/home/ryan/.nvm/versions/node/v87.. 0/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/home/ryan/.nvm/versions/node/v87.. 0
linux x64 4.8. 0- 58-generic
registry=http://registry.npm.taobao.org
Copy the code
Unfortunately, updating and replacing the NPM requires reinstalling the CNPM. This is recommended:
Add alias to ~/.bashrc:
echo '#alias for cnpm alias cnpm="npm --registry=https://registry.npm.taobao.org --cache=~/.npm/.cache/cnpm --disturl=https://npm.taobao.org/dist --userconfig=~/.cnpmrc"' >> ~/.bashrc && source ~/.bashrc
Copy the code
This way, no matter what version NPM switches, CNPM can use:
ryan@ryan- 900.X5L:~$ node -v
v87.. 0
ryan@ryan- 900.X5L:~$ cnpm -v
5.42.
ryan@ryan- 900.X5L:~$ nvm ls
iojs-v33.1.
v611.4.
-> v87.. 0
default -> node (-> v87.0).node -> stable (-> v87.. 0) (default)
stable -> 8.7 (-> v87.. 0) (default)
iojs -> iojs-v33. (-> iojs-v33.1.) (default)
lts/* -> lts/boron (-> v611.4.)
lts/argon -> v48.4.(- >N/A)
lts/boron -> v611.4.
ryan@ryan- 900.X5L:~$ nvm use 6.114.
Now using node v611.4. (npm v310.10.)
ryan@ryan- 900.X5L:~$ cnpm -v
3.1010.
Copy the code
If I close terminal, I open it again
ryan@ryan- 900.X5L:~$node The program "node" is not installed. To install nodejs-legacy, run the following command: sudo apt install nodejs-legacy
Copy the code
What the hell? Don’t put on?
If this happens, you can look at the current NVM LS and see that no node version is specified. In this case, NVM use 6.11.4 specifies a version.
Installation of yarn
With reference to yarnpkg.com/zh-Hans/doc…
Set Taobao Mirror
yarn config set registry https://registry.npm.taobao.org
Copy the code
reference
- Github.com/alsotang/no…
- Fengmk2.com/blog/2014/0…
- github.com/cnpm/nvm
- npm.taobao.org/
- Yarnpkg.com/zh-Hans/doc…