ubuntu14.10下安装nodejs_hexo静态博客

如果对版本没要求,直接安装:

1
2
3
sudo apt-get install nodejs
nodejs -v #查看版本成功则安装成功
sudo apt-get install npm

或者
curl http://npmjs.org/install.sh | sh
权限不够的话:
curl http://npmjs.org/install.sh | sudo sh

为了防止node不被识别成nodejs,安装nodejs-legacy

1
2
sudo apt-get install nodejs-legacy
sudo npm install -g hexo

出现graceful-fs问题的话:

1
2
3
4
5
git clone git://github.com/isaacs/npm.git
cd npm/scripts
chmod +x install.sh
sudo ./install.sh
sudo npm install -g hexo

找个地方开始建项目了:

1
2
3
4
5
6
7
8
mkdir blog
cd blog
mkdir xiaoyue26
cd xiaoyue26
sudo hexo init #sudo hexo init <folder>
sudo npm install
sudo hexo generate
sudo hexo server

打开显示的ip进去看看。

(1)如果是用以前的博客的话,复制以前的博客备份xiaoyue.tar.gz,解压打开。添加新博客内容:先从作业部落下载自己写好的md文件,用notepad++转为utf-8编码。
然后rz进客户机中。跳到步骤(3).

(2)如果是第一次配置的话,从新开始配置:
改_config.yml最后三行:

1
2
3
4
deploy:
type: git
repository: git@github.com:xiaoyue26/xiaoyue26.github.io.git
branch: master

其中也可以是repository: http://github.com/xiaoyue26/xiaoyue26.github.io.git
可以省去github上添加ssh公钥的步骤。

然后命令行:
sudo npm install hexo-deployer-git --save
查看github添加ssh公钥笔记
(3)
hexo new post vagrant笔记
撰写source/__posts/vagrant笔记.md中的正文内容。

1
2
hexo g
hexo d

两句可合并为hexo d -g
浏览器输入
http://xiaoyue26.github.io
访问博客。


1.hello.js:

1
2
3
4
5
6
7
8
var http = require('http');
http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello World\n');
}).listen(1337);
//若写listen(1337,"127.0.0.1")则只能从本机访问;
//所以将后面的ip去掉。
console.log('Server running at http://127.0.0.1:1337');

2.查看端口相关:
查看本机的8080端口是谁在监听(或占用)
lsof -i:8080
查看正在连接的双方端口:
netstat (有所遗漏)
ss -t -a (有所遗漏)

推荐文章