[Git Bash]
mkdir testvm/
cd testvm/
vagrant init bento/ubuntu-22.04
vi Vagrantfile
---
config.vm.network "private_network", ip: "192.168.56.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end
---
vagrant up
vagrant ssh
[VM内]
rbenvを使ってのrubyコマンドのインストール
sudo apt update
sudo apt upgrade -y
sudo apt install -y gcc make libssl-dev libreadline-dev zlib1g-dev libyaml-dev build-essential checkinstall
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL -l
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 3.2.1 (10分ほどかかる)
rbenv global 3.2.1
ruby -v
nodeコマンドとyarnコマンドをインストール
sudo apt install -y nodejs npm
sudo npm install n -g
sudo n stable
sudo apt purge -y nodejs
exec $SHELL -l
sudo npm install yarn -g
node -v
yarn -v
アプリを作成
mkdir example_project
cd example_project/
bundle init
vi Gemfile
---
# gem "rails"
gem "rails"
---
bundle install
# bundle install --path vendor/bundle という説も
bundle exec rails new .
⇒ Overwrite /home/vagrant/example_project/Gemfile? (enter "h" for help) [Ynaqdhm] y と入力
rails -v
Rails 7.0.4.2
Railsアプリを起動
cd example_project/
bundle exec rails s -b 192.168.56.10
Ctrl + C
ブラウザでアクセス(初回アクセス時は少々時間がかかります)
⇒http://192.168.56.10:3000