LoginSignup
1
1

More than 3 years have passed since last update.

Linux(ubuntu)にruby on rails 6.0の環境構築をする(2020.4.1)

Posted at

どうものぶおです
今回はubuntuでruby on rails6の開発環境を作っていきます

これまでmacで開発していたんですが、別に持っていたwindowsのPCをHDDからSSDに変換して超サクサクに動くようになったため、こちらでruby on rails を使えるようにしていきたいと思います

Rubyをインストール

インストールに必要なaptを更新します

sudo apt-get update
sudo apt-get -y install git curl g++ make zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev sqlite3 libsqlite3-dev nodejs

ホームディレクトリに移動します

cd
git clone git://github.com/sstephenson/rbenv.git .rbenv

パスを通します

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
mkdir -p ~/.rbenv/plugins

作成したディレクトリに移動

cd ~/.rbenv/plugins

git上のファイルをクローンします

git clone git://github.com/sstephenson/ruby-build.git

rubyのバージョン(今回は2.6.3)を指定してinstallします

rbenv install 2.6.3

使用するrubyのバージョンをコンピュータに知らせます

rbenv global 2.6.3

rubyが正常にインストールされているか確認します(バージョンが表示されます)

ruby -v

Ruby on railsをインストール

(最新版の6.0がインストールされます)

gem install rails

実際にRailsで作成できるか確認

まずはアプリを作成します

rails new sampe-app

作成したアプリのディレクトリに移動します

cd sample-app

サーバーを起動

rails s

しかし以下のようなエラーが・・・。

︙
 Webpacker configuration file not found /home/nobu/.rbenv/plugins/sample-app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory

書いてあるとおり rails webpacker:installを実行してみると今度は別のエラーが

Yarn executable was not detected in the system.

Yarnがないのでインストールすることに

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

完了しました。
もう一度webpackerをインストール

rails webpacker:install

完了したらもう一度'rails s'でサーバーを起動し、ブラウザ(chromeやexplolerなど)でいかにアクセスします
(わからない人はコピーして検索欄に貼り付けましょう)

localhost:3000

これで以下のような画面がでたら完了です
(わーい)

Screenshot from 2020-04-01 23-22-12.png

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