Centos 6.4安装Nodejs和npm

安装python

由于nodejs的最新版本都要求python版本必须在2.7以上,所以要先升级python,我们查看一下机器现有的python版本。

1
[root@localhost ~]# python -v

我的环境默认是python 2.6.6版本。乖乖升级吧。可以使用下面的命令直接下载解压,也可在浏览器中打开http://python.org/ftp/python/ 选择自己需要的版本下载然后解压,我安装的是Python-2.7.6rc1版本。

1
2
[root@localhost ~]# wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
[root@localhost ~]# tar xjf Python-2.7.3.tar.bz2

开始安装python

1
2
3
4
5
6
[root@localhost 下载]# cd Python-2.7.6rc1
[root@localhost Python-2.7.6rc1]# ./configure
[root@localhost Python-2.7.6rc1]# make all
[root@localhost Python-2.7.6rc1]# sudo make install
[root@localhost Python-2.7.6rc1]# make clean
[root@localhost Python-2.7.6rc1]# make distclean

依次执行完上述命令后,重启机器,然后再次查看python版本,显示安装成功。

1
2
3
4
[root@localhost ~]# python -v
Python 2.7.6rc1 (default, Jan 12 2014, 16:31:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

安装nodejs

安装必要的make以及gcc,gcc-c++编译器

1
[root@localhost ~]# yum -y install make gcc gcc-c++

安装nodejs

1
2
3
4
5
[root@localhost ~]# wget http://nodejs.org/dist/v0.10.15/node-v0.10.15.tar.gz
[root@localhost ~]# tar xzf node-v0.10.15.tar.gz
[root@localhost 下载]# cd node-v0.10.15
[root@localhost node-v0.10.15]# ./configure
[root@localhost node-v0.10.15]# make && make install

运行安装npm的脚本

1
2
3
4
5
[root@localhost ~]# curl https://npmjs.org/install.sh | sudo sh
[root@localhost ~]# node -v
v0.10.15
[root@localhost ~]# npm -v
1.3.5

—EOF—