首页 > 编程知识 正文

如何用nodejs搭建服务端(搭建node)

时间:2023-05-04 08:04:11 阅读:77338 作者:2068

今天闲来无事,看到自己阿里云上面之前安装过的node,版本v.0*,一看官网都已经v5.*了,所以毅然决定升级版本,但是。。。。。 碰到了好多问题

首先未大家分享如何升级node.js

首先安装n模块:

[sourcecode language="plain"]npm install -g n[/sourcecode]

第二步:

升级node.js到最新稳定版

[sourcecode language="plain"]n stable[/sourcecode]

n后面也可以跟随版本号升级指定版本比如:

[sourcecode language="plain"]n v0.10.26[/sourcecode]

或者

[sourcecode language="plain"]n 0.10.26[/sourcecode]

就是这么的简单即可升级node

为大家送上一些npm常见命令

[sourcecode language="plain"]

npm -v #显示版本,检查npm 是否正确安装。

npm install express #安装express模块

npm install -g express #全局安装express模块

npm list #列出已安装模块

npm show express #显示模块详情

npm update #升级当前目录下的项目的所有模块

npm update express #升级当前目录下的项目的指定模块

npm update -g express #升级全局安装的express模块

npm uninstall express #删除指定的模块

[/sourcecode]

如果不想升级node 想直接安装的话

从官网下载你想要安装的node版本

下面附上步骤

[sourcecode language="plain"]

tar zxvf node-v0.9.0.tar.gz

cd node-v0.9.0

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

make

make install

[/sourcecode]

顺利的话会直接安装完毕,执行

[sourcecode language="plain"]node -v[/sourcecode]

即可查看最新安装的node版本号

然而升级的过程中会出现常见的问题

[sourcecode language="plain"]collect2: fatal error: cannot find 'ld'[/sourcecode]

解决办法

[sourcecode language="plain"]

第一种<a rel="external nofollow" href="https://github.com/nodejs/node/issues/4212">解决办法</a>

第二种./configure --without-snapshot编译的时候加参数

[/sourcecode]

还会碰到gcc版本较低无法安装或者安装完之后无法使用命令,则需要升级gcc,详见下面步骤

[sourcecode language="plain"]

1.1 获取安装包并解压

wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2

tar -jxvf gcc-4.8.2.tar.bz2

1.2 下载供编译需求的依赖项

cd gcc-4.8.0

./contrib/download_prerequisites

1.3 建立一个目录供编译出的文件存放

mkdir gcc-build-4.8.2

cd gcc-build-4.8.2

1.4 生成Makefile文件

../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

1.5 编译(注意:此步骤非常耗时)

make -j4

1.6、安装

sudo make install

[/sourcecode]

-j4选项是make对多核处理器的优化,如果不成功请使用 make,相关优化选项可以移步至参考文献[2]。

验证安装

[sourcecode language="plain"]gcc -v #重启[/sourcecode]

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。