AWSを利用したRuby on Rails環境構築 #2
Linuxサーバの構築
パッケージのアップデート
- ターミナル(ec2-user 以下同様)
$ sudo yum -y update $ sudo yum -y install git make gcc-c++ patch libyaml-devel libffi-devel libicu-devel zlib-devel readline-devel libxml2-devel libxslt-devel ImageMagick ImageMagick-devel openssl-devel libcurl libcurl-devel curl
※ -y; 全ての問いにYesと回答するコマンド.
Node.jsのインストール
サーバサイドのJavaScriptパッケージ.CSSや画像を圧縮する際に使用.
- ターミナル
$ sudo curl -sL https://rpm.nodesource.com/setup_6.x | sudo bash - DEPRECATION WARNING Node.js 6.x LTS Boron is no longer actively supported! You will not receive security or critical stability updates for this version. You should migrate to a supported version of Node.js as soon as possible. Use the installation script that corresponds to the version of Node.js you wish to install. e.g. https://deb.nodesource.com/setup_10.x — Node.js v10 LTS "Dubnium" (recommended) https://deb.nodesource.com/setup_12.x — Node.js v12 LTS "Erbium" Please see https://github.com/nodejs/Release for details about which version may be appropriate for you. The NodeSource Node.js distributions repository contains information both about supported versions of Node.js and supported Linux distributions. To learn more about usage, see the repository: https://github.com/nodesource/distributions
rbenvとruby-buildのインストール
rbenvはrubyのバージョンを管理するパッケージで,ruby-buildはそのプラグイン.
- ターミナル
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile $ source .bash_profile $ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build $ rbenv rehash
Rubyのインストール
今までのコマンドでミス等があるとRubyインストールでエラーが発生してしまう.
BUILD FAILED (Amazon Linux AMI 2018.03 using ruby-build 20200224-4-g0ef5e05) Inspect or clean up the working tree at /tmp/ruby-build.20200310235320.30555.GI0AMO Results logged to /tmp/ruby-build.20200310235320.30555.log Last 10 log lines: tool/config.sub already exists checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/tmp/ruby-build.20200310235320.30555.GI0AMO/ruby-2.5.1': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
- ターミナル
$ rbenv install 2.5.1 $ rbenv global 2.5.1 $ rbenv rehash $ ruby -v