linux下的nodejs安装

 
linux下安装nodejs的方式:
1、源码安装
2、nvm安装
这里推荐使用nvm安装,避免下载nodejs源码;
 
安装步骤:

一、安装git

       一般linux系统的git版本都比较旧,使用容易出现问题,所以首先要更新git

1、卸载旧版本git

CentOS:
# yum remove git
Ubuntu:
# sudo apt-get remove --purge git
 

2、安装新版本git

安装依赖:
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
安装过程:
# wget https://github.com/git/git/archive/v2.10.2.tar.gz
# tar zxvf v2.10.2.tar.gz
# cd git-2.10.2
# make configure
# ./configure
# make all doc
# make install install-doc install-html

注:在make all doc步骤时如果出现错误,按照错误提示分别安装以下依赖,然后重新make all doc

# yum install perl-ExtUtils-MakeMaker
# cd ..
# wget https://sourceforge.net/projects/asciidoc/files/asciidoc/8.6.9/asciidoc-8.6.9.tar.gz
# tar -xzvf asciidoc-8.6.9.tar.gz
# cd  asciidoc-8.6.9
# ./configure
# make
# make install
# cd ..
# cd git-2.10.2
# yum install libxslt
# yum install xmlto
# yum install docbook2X
查看版本号:
# git --version
> git version 2.10.2

二、安装nvm

# cd ~/git
# git clone https://github.com/cnpm/nvm.git
配置自动执行,将以下内容写入~/.bashrc
source ~/git/nvm/nvm.sh
 
查看nvm版本:
# source ~/.bashrc
# nvm --version
> 0.26.1
 

三、安装nodejs

查看版本nodejs版本:
# nvm ls-remote
安装特定版本:
# nvm install 7.0.0
# node --version
> v7.0.0
 
使用cnpm代替npm
# npm install cnpm -g --registry=http://registry.npm.taobao.org
# cnpm --version
> 4.4.0
 
 
 
 
 
 
相关链接:
 
原文地址:https://www.cnblogs.com/Zhanxueyou/p/6043826.html