LoginSignup
2
3

More than 3 years have passed since last update.

Railsを動かすために、WebpackerとYarnをインストールする

Posted at

環境

Ubuntu16.04.7 LTS
Windows10 + Vegrant
Rails 6.0.3

やったこと

railsを起動したところ、Webpackerが存在していなので、インストールして下さいのエラーメッセージが表示されるのでインストールする事に。

$ rails s
Webpacker configuration file not found /vagrant/xxx/config/webpacker.yml. 
Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /vagrant/xxx/config/webpacker.yml (RuntimeError)

ところが、Webpackerをインストールしようとすると、今度はYarnをインストールして下さいと出てくる。

$rails webpacker:install
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/

Yarnのインストール方法は、基本、公式サイトを参考にします。
https://classic.yarnpkg.com/en/docs/install/#debian-stable

$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

コマンドの説明
- apt-keyは、既存のキー一覧に新しいキーを追加するコマンド。
- add -を付けると、標準入力からキー一覧に追加するという意味です。
- teeは、標準出力をファイルに書き込み、かつ、画面表示もするコマンド。
- yarnのリモートリポジトリのURLをyarn.listに書き込んでいます。
- stable mainは安定版です。

updateで、パッケージのインデックスファイルを最新にしてから、インストールを行います。パッケージをインストールする前にupdateをするのはお約束です。

$sudo apt update && sudo apt install yarn

コマンドの説明
コマンド1 && コマンド2 で、コマンド1が正常終了すればコマンド2を実行するという意味です。

Yarnがインストールされた事を確認します。

$yarn --version
1.22.5

rails sが正しく動作するようになりました。

$ rails s
2
3
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
3