nodejs环境安装

centos7安装nodejs环境

原文地址:
https://www.cnblogs.com/MY0101/p/6625344.html

下载地址:
https://nodejs.org/dist/v7.9.0/node-v7.9.0-linux-x64.tar.gz

安装node
tar xvf node-v7.9.0-linux-x64.tar.xz
移到 /opt/

添加环境变量

node -v #查看版本
npm  -v  #查看版本
npm -g install npm@latest #npm升级到最新版本


npm版本管理
npm install npm@latest -g #升级到最新版本
npm install npm@4.2.0 -g #npm换成这个版本

#npm使用淘宝源

npm config set registry https://registry.npm.taobao.org


node版本管理
1.首先安装n模块
npm install -g n
2.升级node.js到最新稳定版
n stable (会在/usr/local/bin/下生成node npm 等命令) n后面也可以跟随版本号比如:(n v0.10.26)

3.重新登陆bash

node -v

npm -v 

可以看到已经是新版本了。




部署node代码成静态文件:
在代码的根目录执行如下:
npm install
npm run build
生成dist目录,此目录里的文件就是静态文件


#安装yarn
npm install -g yarn

 nvm管理nodejs(好用)

原文:http://www.cnblogs.com/qq4535292/p/9848040.html
NVM git地址: https://github.com/creationix/nvm

1. 下载命令

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
wget --no-check-certificate -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
--------------------- 2、下载完成后加入系统环境 source ~/.bashrc 4、安装需要的node版本 #查看有哪些版本可用 https://nodejs.org/dist/
nvm ls-remote #查看远程可用版本
nvm install 10.13.0 5. 查看当前机器已安装版本号 nvm list 6. 切换node版本 nvm use 10.13.0 7、设置默认的node版本 nvm alias default v9.5.0


 ##安装cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org




#npm使用淘宝源

#npm config set registry https://registry.npm.taobao.org

 
原文地址:https://www.cnblogs.com/hanxiaohui/p/9377634.html