Vagrant上のCentOSにNode.jsをインストール
を参考に、自分用の開発環境を作る。その時に詰まったところなどのメモ。
※Vagrant+VirtualBoxは導入済みとします。
vagrant up
vagrant ssh
[vagrant@vagrant-centos65 ~]$ pwd
/home/vagrant
[vagrant@vagrant-centos65 ~]$ uname -a
Linux vagrant-centos65.vagrantup.com 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[vagrant@vagrant-centos65 ~]$ cat /etc/redhat-release
CentOS release 6.5 (Final)
nodebrew のインストール
nodebrewで管理と楽と先輩に聞いたのでさくっとREADMEに書いてあるのでその手順で導入。
...しようとしたらコケたのでメモ
なぜかコマンドはあるもののcurlできない
[vagrant@vagrant-centos65 ~]$ curl -L git.io/nodebrew
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Host name provided via SNI and via HTTP are different</p>
</body></html>
wgetでためそうとしたらwgetがないのでyum install
[vagrant@vagrant-centos65 ~]$ which yum
/usr/bin/yum
[vagrant@vagrant-centos65 ~]$ which wget
/usr/bin/which: no wget in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
[vagrant@vagrant-centos65 ~]$ sudo yum install wget
~~しばらくまつ
yを押す
Complete!
気を取り直して
[vagrant@vagrant-centos65 ~]$ wget git.io/nodebrew
あとは出てくるやつに従って
========================================
Add path:
export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================
[vagrant@vagrant-centos65 ~]$ export PATH=$HOME/.nodebrew/current/bin:$PATH
[vagrant@vagrant-centos65 ~]$ which nodebrew
~/.nodebrew/current/bin/nodebrew
とnodebrewが使えるように。
nodebrewからnodeのインストール
とりあえずstable(2015/04現在v0.12.2)とv0.10系を入れておく
nodebrew install-binary v0.10.x
nodebrew install-binary stable
- 入れたらちゃんとuseしておく
nodebrew use v0.12.2
- aliasをつけておくのも良い
nodebrew alias v12 v0.12.2
nodebrew alias v10 v0.10.38
(nodebrew lsしたときにperlのwarningがうるさいので.bashrcに以下を記述した)
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
nodeでhello world
vimを入れる(好みによる)
sudo yum -y install vim
適当にtest.jsとかで
touch test.js
vim test.js
下記をコピペで
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "192.168.33.10");
console.log('Server running’);
node test.js
で192.168.33.10:1337 にアクセスするとhello worldがみれる
ひとまずこれでVagrant上でNode.jsの動く環境が構築できたはず。
(次はExpress とかを入れる)