Linux安装Node.js(源码编译安装)
2015-06-01 16:54
746 查看
环境:
Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic i686)
下载Node.js安装包,请参考网址:http://nodejs.org/download/
这里选择源码包安装方式,安装过程如下:
登陆到Linux终端,进入/usr/local/src目录,如下:
root@ubuntu:~# cd /usr/local/src/
下载nodejs安装包:
2,解压文件并安装
到此整个安装已经完成,如果在安装过程有错误问题,请参考以下解决: 可能出现的问题:
The program 'make' is currently not installed. You can install it by typing: apt-get install make
按照它的提示,使用命令
# apt-get install make
g++: Command not found 没有安装过g++,现在执行安装:
#apt-get install g++
测试程序 hello.js:
# node helloworld.js
另外的一个实例:WebServer
这个简单Node 编写的 Web服务器,为每个请求响应返回“Hello World”。
要运行服务器,将代码编写到文件example.js 并执行 node 程序命令行:
Server running at http://127.0.0.1:1337/
有兴趣的朋友可以尝试下面一个简单的TCP服务器监听端口1337 并回应的一个例子:
Ubuntu 12.04.2 LTS (GNU/Linux 3.5.0-23-generic i686)
下载Node.js安装包,请参考网址:http://nodejs.org/download/
这里选择源码包安装方式,安装过程如下:
登陆到Linux终端,进入/usr/local/src目录,如下:
root@ubuntu:~# cd /usr/local/src/
下载nodejs安装包:
#wget http://nodejs.org/dist/v0.10.17/node-v0.10.17.tar.gz
2,解压文件并安装
# tar xvf node-v0.10.17.tar.gz # cd node-v0.10.17 # ./configure # make # make install # cp /usr/local/bin/node /usr/sbin/ 查看当前安装的Node的版本 # node -v v0.10.17
到此整个安装已经完成,如果在安装过程有错误问题,请参考以下解决: 可能出现的问题:
The program 'make' is currently not installed. You can install it by typing: apt-get install make
按照它的提示,使用命令
# apt-get install make
g++: Command not found 没有安装过g++,现在执行安装:
#apt-get install g++
测试程序 hello.js:
console.log("Hello World");
# node helloworld.js
另外的一个实例:WebServer
这个简单Node 编写的 Web服务器,为每个请求响应返回“Hello World”。
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337); console.log('Server running at port 1337 ');
要运行服务器,将代码编写到文件example.js 并执行 node 程序命令行:
# node example.js
Server running at http://127.0.0.1:1337/
有兴趣的朋友可以尝试下面一个简单的TCP服务器监听端口1337 并回应的一个例子:
var net = require('net'); var server = net.createServer(function (socket) { socket.write('Echo server\r\n'); socket.pipe(socket); }); server.listen(1337, '127.0.0.1');
相关文章推荐
- linux学习笔记—逻辑操作符和管道符
- linux下查看最消耗CPU、内存的进程
- Linux下ln链接命令详解
- Linux下which、whereis、locate、find 命令的区别
- 9种企业常用的Linux和Unix服务器
- 两台linux服务器器同步目录脚本
- Linux下分区详解之-Parted
- 修改linux文件权限命令:chmod
- Linux下java项目的makefile
- linux:交叉编译后程序的下载方式
- Linux查看端口信息命令
- Windows/Linux下引用jar包,并用javac/java编译运行
- mac下压缩mp3音频文件/linux 适用
- linux修改默认语言
- CentOS上安装Bugzilla 4.5.2
- linux下解压命令大全(转)
- centos6.3系统python2.6.6升级到python2.7.9
- Mysql误删root用户或没有root用户――linux
- Linux Ctrl+Z的使用方法
- linux学习笔记—输出重定向