我的Node.Js学习记录-安装
之前在很多地方听说过,今天再次感觉,要试用下了。
通过官网 :nodejs.org来到如下地址:
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
看到如下内容:
sudo apt-get install python-software-propertiessudo add-apt-repository ppa:chris-lea/node.jssudo apt-get updatesudo apt-get install nodejs我是ubuntu11.10所以如下:banxi1988@banxi:~$ sudo apt-get install python-software-properties[sudo] password for banxi1988: 正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 python-software-properties 已经是最新的版本了。下列软件包是自动安装的并且现在不需要了: libboost-program-options1.46.1 libboost-thread1.46.1 libboost-date-time1.46.1使用'apt-get autoremove'来卸载它们升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 1 个软件包未被升级。banxi1988@banxi:~$ sudo add-apt-repository ppa:chris-lea/node.jsYou are about to add the following PPA to your system: node.js Evented I/O for V8 javascript. Node's goal is to provide an easy way to build scalable network programs More info: https://launchpad.net/~chris-lea/+archive/node.jsPress [ENTER] to continue or ctrl-c to cancel adding itExecuting: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.YQfhww6Vw5 --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80/ --recv 136221EE520DDFAF0A905689B9316A7BC7917B12gpg: 下载密钥‘C7917B12’,从 hkp 服务器 keyserver.ubuntu.comgpg: 密钥 C7917B12:公钥“Launchpad chrislea”已导入gpg: 合计被处理的数量:1gpg: 已导入:1 (RSA: 1)banxi1988@banxi:~$ banxi1988@banxi:~$ sudo apt-get install nodejs正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: libboost-program-options1.46.1 libboost-thread1.46.1 libboost-date-time1.46.1使用'apt-get autoremove'来卸载它们将会安装下列额外的软件包: rlwrap下列【新】软件包将被安装: nodejs rlwrap升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。需要下载 3,037 kB 的软件包。解压缩后会消耗掉 8,577 kB 的额外空间。您希望继续执行吗?[Y/n]y获取:1 http://mirrors.163.com/ubuntu/ oneiric/universe rlwrap i386 0.37-2 [75.2 kB]获取:2 http://ppa.launchpad.net/chris-lea/node.js/ubuntu/ oneiric/main nodejs i386 0.6.11-1chl1~oneiric1 [2,962 kB]下载 3,037 kB,耗时 17秒 (176 kB/s) 选中了曾被取消选择的软件包 rlwrap。(正在读取数据库 ... 系统当前共安装有 235474 个文件和目录。)正在解压缩 rlwrap (从 .../rlwrap_0.37-2_i386.deb) ...选中了曾被取消选择的软件包 nodejs。正在解压缩 nodejs (从 .../nodejs_0.6.11-1chl1~oneiric1_i386.deb) ...正在处理用于 man-db 的触发器...正在设置 rlwrap (0.37-2) ...update-alternatives: 使用 /usr/bin/rlwrap 来提供 /usr/bin/readline-editor (readline-editor),于 自动模式 中。正在设置 nodejs (0.6.11-1chl1~oneiric1) ...banxi1988@banxi:~$
相当顺利。然后,
测试一个Hello,world.
来自如下地址:
http://nodejs.org/docs/latest/api/synopsis.html
代码:var http = require('http');http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n');}).listen(8124);console.log('Server running at http://127.0.0.1:8124/');
然后运行:
[code="shell]
> node example.js
Server running at http://127.0.0.1:8124/
然后打开浏览器,输入上面的地址就可以看到亲切的hello,world!了!