npm安装(Centos7)

** 在 Linux 非 root 用户下 sudo npm npm 命令执行的 node_module 地址不一样 **

推荐个https://npm.taobao.org/mirrors/
可以下载想要的node版本

首先安装必要的环境(推荐方式一安装)

1
yum install gcc gcc-c++

一、方式一

1
wget https://npm.taobao.org/mirrors/node/v10.14.1/node-v10.14.1-linux-x64.tar.gz

然后执行下面命令

1
2
tar -xvf  node-v8.0.0-linux-x64.tar.xz
mv node-v8.1.4-linux-x64 node

配置环境变量

1
vim /etc/profile

在文件中添加,目录写自己的实际目录

1
2
3
#set for nodejs  
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH

生效配置文件

1
2
3
source /etc/profile
node -v
npm -v

二、方式二下载源码(make很浪费时间,但可以体验编译的乐趣)

1
wget https://npm.taobao.org/mirrors/node/v10.13.0/node-v10.13.0.tar.gz

解压安装

1
2
3
4
5
tar xvf node-v10.13.0.tar.gz
cd node-v10.13.0/
./configure
make #这个操作可能会很久
make install
over ,npm -v 看版本

三、其它操作,比如换个源

1
2
npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm -v
不想用cnpm操作,那就直接换npm源
  • 单次使用
    1
    npm install --registry=https://registry.npmmirror.com
  • 永久使用
    1
    npm config set registry https://registry.npmmirror.com
  • 检测是否成功
    1
    2
    3
    4
    #配置后可通过下面方式来验证是否成功
    npm config get registry
    #或
    npm info express

本文地址 npm安装(Centos7)

本文地址: https://github.com/maxzhao-it/blog/post/42920/