Hits: 218

本人电信技术背景,非码农,未学习过linux,对码农和linux向来抱有好感,只是觉得其事颇苦逼,从未操练。春节前后闲暇,在qingcloud和阿里云搭建了freeswitch,有了点基本上手操作,如apt-get, yum, npm, make,git等反复操练, VIM也略有把玩。今天花了一个多小时学会了搭建Nodejs,步骤谨记。

在阿里云ECS的单核1G最小实例上建Ubuntu14.x 64bit虚机,apt-get 不得nodejs的包,原来是apt-get没有sources.list文件。VIM自己来写吧,

sudo vim /etc/apt/sources.list 
阿里云源
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

存盘退出后, 执行

sudo apt-get update

sudo apt-get install npm

npm install -g n

N过去叫NVM,是Nodejs的管理器。运行n –help即可看到N的使用说明。

运行n latest ,安装最新版Nodejs6.2.2, 通过n安装的Node都在/usr/local/n/versions/node/6.2.2目录里。

现在Nodejs已经建好,可以搭建http服务了。Node的用法可以用node –help来查看。

在6.2.2的目录里写一段js来生成最简单的HTTP服务器吧:hello world, 你知道的。

然后运行nodejs app.js, 打开浏览器访问http://127.0.0.1(或公网IP):3000。

Nodejs demo

搞定!其实不然,飞机起飞了, 还没落地,又研究了一个小时,竟然还不会关掉Nodejs,kill -9 PID不灵啊。。

万事皆有定数,可是时间永远不定,只好先到此为止了

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.