introduction:
Not long windows
on the allocated over node
remember previous node environment variable to add NODE_PATH
to the user variables, and then introduced into the system variables NODE_PATH
, and npm install
global package directory will be stored in C:/Users[用户]/administrator[你的计算机名字]/AppData/Roaming/npm
the directory, and now looks like a more advanced approach!
Summary of traditional methods:
- Npm package global directory:
C:/Users/[username]/AppData/Roaming/npm/node_modules
- Npm package global command directory:
C:/Users/[username]/AppData/Roaming/npm
- Npm actually finds the directory of the global command:
C:/Users/[username]/.npmrc
theprefix
value of the file content - Npm package global cache directory:
C:/Users/[username]/.npmrc
thecache
value of the file content - Need to configure system environment variables: Computer -> Properties -> Advanced System Configuration -> Environment Variables ->
PATH/NODE_PATH
…balabala~~~
1. The new method of node configuration (take windows as an example)
- .npmrc location
C:/Users/[username]/.npmrc
- Create in the node installation directory
/nodejs/node_global
and/nodejs/node_cache
store the global package in two folders - Node installation directory in this example
D:/node
- The package directory of the global package installation after the success of this example
D:/node/nodejs/node_global/lib/node_modules
1.node installation directory
安装node到[D:/node]下
2. Modify the default global catalog
Method 1: Go to the node installation directory [D:/node] and execute the following command:
npm config set prefix D:/node/nodejs/node_global/ //全局包目录,就在node安装目录新建了个nodejs文件夹存放
npm config set cache D:/ndoe/nodejs/node_cache/ //全局包缓存目录,就在node安装目录新建了个nodejs文件夹存放
Method Two
Modify C:/Users/[username]/.npmrc
the cache
value and prefix
value of the file directly , the file is as follows:
prefix=D:\node\nodejs\node_global
cache=D:\node\nodejs\node_cache
registry=https://registry.npm.taobao.org/
3. Configure environment variables
Computer->Properties->Advanced System Configuration->Environment Variables->User Variables->Edit path
, add the `global" directory as follows:
PATH: D:\node\nodejs\node_global\;
to sum up:
- No need to add system environment variables
NODE_PATH
, just edit user environment variables - The package installation is unified to the node installation package directory for easy management and query
- Just modify
.npmrc
one file - Before
path
might have an impact, do not delete the entry into force of the original environmentpath
ofnode
relevant content, try to restart the machine
Two, Linux node/npm initialization environment variable configuration
1. .npmrc modification
- .npmrc file location
~/.npmrc
- Still create two folders node_global and node_cache to store global packages
- In this example, the node installation directory is
/SOFTWARE/node-v8.9.4-linux-x64/
step1:
vi ~/.npmrc
step2:
enter the following
prefix=/SOFTWARE/node-v8.9.4-linux-x64/nodejs/node_global
cache=/SOFTWARE/node-v8.9.4-linux-x64/nodejs/node_cache/
/SOFTWARE/node-v8.9.4-linux-x64/
Is my installation package path, replace it with your actual situation
step1 & step2 can also be directly typed as the following command
npm config set prefix /SOFTWARE/node-v8.9.4-linux-x64/nodejs/node_global/ //全局包目录,就在node安装目录新建了个nodejs文件夹存放
npm config set cache /SOFTWARE/node-v8.9.4-linux-x64/nodejs/node_cache/ //全局包缓存目录,就在node安装目录新建了个nodejs文件夹存放
2. Global variable configuration
step1:
vi /etc/profie
step2:
Enter the following content, add NODE_PATH
other variables
NODE_HOME=/SOFTWARE/node-v8.9.4-linux-x64
NODE_PATH=$NODE_HOME/nodejs/node_global/:$PATH
PATH=$NODE_PATH/bin:$PATH
step3: test
npm install -g pm2 forever
pm2 // 如果未配置成功,会出现pm2: command not found