LoginSignup
2
1

More than 5 years have passed since last update.

Vagrantでrails serverをするまで

Posted at

メモ

環境

・windows10
・Vagrant 2.0.3
・virtualbox 5.2.8
・box->centos/7 (https://app.vagrantup.com/centos/boxes/7)

作業用フォルダを作成

(C:\Users\ユーザーネーム\MyVagrant)を作成
(C:\Users\ユーザーネーム\MyVagrant\App1)を作成

コマンドプロントを開いてApp1に移動

$ cd C:\Users\ユーザーネーム\MyVagrant\App1

Vagrantfile作成

vagrant init centos/7

Vagratnfile

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "forwarded_port", guest: 3000, host: 3000
  config.vm.synced_folder "./share", "/vagrant", type: "virtualbox", create: "true"
end
$ vagrant up 
$ vagrant ssh

RVM

現在の場所

$ pwd

→/home/vagrant

インストール

$ curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
$ curl -sSL https://get.rvm.io | bash -s stable

PATHを通す

//ディレクトリ内
$ ls -a // .bash_history /bash_logout .bash_profile ...

//.bash_profileを編集
$ vi .bash_profile

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

export PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH=$PATH:$HOME/.rvm/bin //←これを追加

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
$ source .bash_profile //更新

Ruby

インストール

//インストール可能なバージョン
$ rvm install -l

$ rvm install 2.4.1

Rails

インストール

$ gem install rails

//とりあえず全gemをupdateしとく
$ gem update

virtualbox側のfirewallを無効にする

firewallを無効にしておかないとつながりません。

# firewalld を無効にする
$ sudo systemctl stop firewalld.service

# OS 起動時もfirewalldが起動しないようにする
$ sudo systemctl mask firewalld.service
$ sudo systemctl list-unit-files | grep firewalld

aa

//共有フォルダに移動
$ cd /vagrant

windowsの(C:\Users\ユーザーネーム\MyVagrant\App1\share)とvagrantの(/vagrant)は共有されています。

$ vi Gemfile

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
..
# gem 'mini_racer', platforms: :ruby //ここの#を外す
..
        ⇓
..
gem 'mini_racer', platforms: :ruby
..
$ bundle install

アプリを作成

//作成
$ rails new TestApp

//TestAppに移動
$ cd TestApp

//サーバー起動
$ rails s -b 0.0.0.0

以上でサーバー起動までの道順でした。
windows側のブラウザで( http://localhost:3000 )と入力すると
起動できたのが確認できると思います。

2
1
0

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
2
1