LoginSignup
3
4

More than 5 years have passed since last update.

vagrant上のUbuntuでMeteorアプリを動かす

Last updated at Posted at 2015-11-28

環境はOS X Yosemite。
vagrant と virtualboxはインストール済み。

$ vagrant -v
Vagrant 1.7.2
$ VBoxManage -v
4.3.30r101610

Mac内の~/workspaceというディレクトリに、yourAppNameという名前のアプリを作成すると仮定し、meteor.vm.local:3000というURLでアプリが公開されるようする。

仮想環境のセットアップ

$ vagrant box add ubuntu https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box
$ cd ~/workspace
$ vagrant init ubuntu

Vagrantfileが作成されるので、29行目付近を以下の様に修正。ipは何でも良い。

Vagrantfile
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.44"

hostsファイルの末尾に以下を追記。

/etc/hostshosts
192.168.33.44    meteor.vm.local

仮想環境を起動。

$ vagrant up

仮想環境に接続。

$ vagrant ssh

仮想環境内での作業

Meteorのインストール。

$ curl https://install.meteor.com/ | sh

Meteorアプリケーション作成。/vagrant直下に作ることで、ローカルのMacの~/workspaceとリンクするため、ローカルのエディタでコーディングができます。

$ cd /vagrant
$ meteor create yourAppName

ここで、

$ cd yourAppName
$ meteor

でアプリを起動しようとすると

$ meteor
[[[[[ /vagrant/yourAppName ]]]]]

=> Started proxy.
Unexpected mongo exit code 45. Restarting.
Unexpected mongo exit code 45. Restarting.
Unexpected mongo exit code 45. Restarting.
Can't start Mongo server.
MongoDB cannot open or obtain a lock on a file

というエラーで起動に失敗する。
色々調べてみると、パーミッションの問題らしい。
https://github.com/TelescopeJS/Telescope/issues/935

このサイトを参考に、以下の手順で解決。

$ cd ~
$ mkdir -p yourAppName/.meteor/local
$ sudo mount --bind /home/vagrant/yourAppName/.meteor/local/ /vagrant/yourAppName/.meteor/local/

上記手順をサーバ起動時に自動で行うようにしておく。

$ echo "sudo mount --bind /home/vagrant/yourAppName/.meteor/local/" >> ~/.bashrc

さて、

$ cd /vagrant/yourAppName
$ meteor

でアプリが起動するので、ブラウザからhttp://meteor.vm.local:3000にアクセスすれば、以下の画面が表示されるはず。

スクリーンショット 2015-11-28 21.53.22.png

あとは、お好きなエディタででコーディングするのみ!

3
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4