下载

cd /mydata
wget http://cdn.npm.taobao.org/dist/node/v10.16.1/node-v10.16.1.tar.gz

解压

cd /mydata
tar -zxf node-v10.16.1.tar.gz

创建安装路径

mkdir /usr/local/node/

设置安装路径

sudo  ./configure --prefix=/usr/local/node/

编译安装

sudo make
sudo make install

增加环境变量

export NODEJS_HOME=/usr/local/node
export PATH=$PATH:$NODEJS_HOME/bin

注意,全程都要用sudo权限,避免目录无法安装

查看安装情况

monster@monster-PC:~$ node -v
v10.16.1
monster@monster-PC:~$ npm -v
6.9.0

TroubleShot

monster@monster-PC:~$ npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN checkPermissions Missing write access to /usr/local/node/lib/node_modules
npm ERR! path /usr/local/node/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/node/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/node/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/node/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/node/lib/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/monster/.npm/_logs/2019-08-05T09_20_52_374Z-debug.log

将目录授权给当前用户

 sudo chown -R monster:monster  /usr/local/node

电脑杂技集团
208 声望32 粉丝

这家伙好像很懂计算机~