Node environment variable configuration, npm environment variable configuration

introduction:

Not long windowson the allocated over noderemember previous node environment variable to add NODE_PATHto the user variables, and then introduced into the system variables NODE_PATH, and npm installglobal package directory will be stored in C:/Users[用户]/administrator[你的计算机名字]/AppData/Roaming/npmthe 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]/.npmrcthe prefixvalue of the file content
  • Npm package global cache directory: C:/Users/[username]/.npmrcthe cachevalue 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_globaland /nodejs/node_cachestore the global package in two folders
  • Node installation directory in this exampleD:/node
  • The package directory of the global package installation after the success of this exampleD:/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]/.npmrcthe cachevalue and prefixvalue 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 .npmrcone file
  • Before pathmight have an impact, do not delete the entry into force of the original environment pathof noderelevant 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_PATHother variables

NODE_HOME=/SOFTWARE/node-v8.9.4-linux-x64
NODE_PATH=$NODE_HOME/nodejs/node_global/:$PATH
PATH=$NODE_PATH/bin:$PATH

Write picture description here
step3: test

npm install -g pm2 forever

Write picture description here

pm2 // 如果未配置成功,会出现pm2: command not found

Write picture description here

Guess you like

Origin blog.csdn.net/jianleking/article/details/79130667
Recommended