LoginSignup
5
2

More than 3 years have passed since last update.

【AWS】EC2にデプロイした時に発生したエラーと解決法

Posted at

アプリをEC2へデプロイした時、発生したエラーと解決法を記録しておきます。
この情報が同じエラーが出た方にお役に立てば嬉しいです。

エラー1:認識されないコマンドライン "-flto"

$ bundle exec cap production deploy

#略

compiling ./libsass/src/emitter.cpp
compiling ./libsass/src/c99func.c
cc1: error: unrecognized command line option "-flto"
make: *** [c99func.o] エラー 1

make failed, exit code 2

Gem files will remain installed in
/var/www/instashot/shared/bundle/ruby/2.6.0/gems/sassc-2.2.0 for inspection.
Results logged to
/var/www/instashot/shared/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/sassc-2.2.0/gem_make.out

An error occurred while installing sassc (2.2.0), and Bundler cannot continue.
Make sure that `gem install sassc -v '2.2.0' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  bootstrap was resolved to 4.3.1, which depends on
    sassc-rails was resolved to 2.1.2, which depends on
      sassc

** DEPLOY FAILED

原因と解決法

ここで注目してほしいのはエラー文のunrecognized command line option "-flto"です。
-fltoというコマンドラインが認識されない原因はgccとg++のバージョンが古いです。
まず、EC2にて確認してみましょう。

[root@ip-172-oo-oo-oo ~]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Copyright (C) 2010 Free Software Foundation, Inc.

[root@ip-172-oo-oo-oo ~]# gcc --version
gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)
Copyright (C) 2010 Free Software Foundation, Inc.
Release Release date
GCC 9.2 August 12, 2019
GCC 9.1 May 3, 2019
GCC 8.3 February 22, 2019
GCC 7.4 December 6, 2018

表より、最新版は9ですが、こちらで7にバージョンアップします。

step_1
# scl-utils-buildのためにインストールする
[root@ip-172-oo-oo-oo ~]# yum install -y iso-codes

# RPMをダウンロードする
[root@ip-172-oo-oo-oo ~]# curl -O http://vault.centos.org/6.5/SCL/x86_64/scl-utils/scl-utils-20120927-11.el6.centos.alt.x86_64.rpm
[root@ip-172-oo-oo-oo ~]# curl -O http://vault.centos.org/6.5/SCL/x86_64/scl-utils/scl-utils-build-20120927-11.el6.centos.alt.x86_64.rpm
[root@ip-172-oo-oo-oo ~]# curl -O http://mirror.centos.org/centos/6/extras/x86_64/Packages/centos-release-scl-rh-2-3.el6.centos.noarch.rpm
[root@ip-172-oo-oo-oo ~]# curl -O http://mirror.centos.org/centos/6/extras/x86_64/Packages/centos-release-scl-7-3.el6.centos.noarch.rpm
step_2
# RPMアップグレードをする
[root@ip-172-oo-oo-oo ~]# rpm -Uvh *.rpm
準備しています...################################# [100%]
更新中 / インストール中...
   1:centos-release-scl-rh-2-3.el6.cen################################# [ 25%]
   2:centos-release-scl-10:7-3.el6.cen################################# [ 50%]
   3:scl-utils-build-20120927-11.el6.c################################# [ 75%]
   4:scl-utils-20120927-11.el6.centos.################################# [100%]
step_3
# STEP 2の4つRPMを削除する(エンターを押してください)
[root@ip-172-31-40-162 ~]# rm *.rpm
rm: 通常ファイル `centos-release-scl-7-3.el6.centos.noarch.rpm' を削除しますか? 
rm: 通常ファイル `centos-release-scl-rh-2-3.el6.centos.noarch.rpm' を削除しますか? 
rm: 通常ファイル `scl-utils-20120927-11.el6.centos.alt.x86_64.rpm' を削除しますか? 
rm: 通常ファイル `scl-utils-build-20120927-11.el6.centos.alt.x86_64.rpm' を削除しますか? 
step_4
# gcc と g++ version 7をインストールする
[root@ip-172-31-40-162 ~]# yum install -y devtoolset-7-gcc-c++ devtoolset-7-make devtoolset-7-build
[root@ip-172-31-40-162 ~]# scl enable devtoolset-7 bash

最後、もう一度バージョンを確認しましょう。

[root@ip-172-oo-oo-oo ~]# gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

[root@ip-172-oo-oo-oo ~]# g++ --version
g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

エラー2:ExecJS::RuntimeUnavailable

$ bundle exec cap production deploy

#略
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Nothing written
rake stderr: rake aborted!
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. 
See https://github.com/rails/execjs for a list of available runtimes.

原因と解決法

Amazon Linux AMIでNode.jsがインストールしていないのは原因です。
EC2にて確認してみましょう。

[root@ip-172-oo-oo-oo ~]# node -v
-bash: node: コマンドが見つかりません

Node.jsをインストールしましょう。

[root@ip-172-oo-oo-oo ~]# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
[root@ip-172-oo-oo-oo ~]# . ~/.nvm/nvm.sh
[root@ip-172-oo-oo-oo ~]# nvm install stable

インストールを完了したら、もう一度確認しましょう。

[root@ip-172-oo-oo-oo node-v12.13.0]# node -v
v13.1.0
[root@ip-172-oo-oo-oo node-v12.13.0]# npm -v
6.12.1

エラー3:SSHKit::Command::Failed

$ bundle exec cap production deploy

#略

Caused by:
SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: bundler: command not found: unicorn
Install missing gem executables with `bundle install`

Tasks: TOP => unicorn:start
(See full trace by running task with --trace)

原因と解決法:

unicorn v5.5.0がバグがありそうなので、バージョンを下たところ解決しました。

Gemfile
gem "unicorn", "~> 5.4"
$ bundle install


ここまでお読みいただきありがとうございました。
来日2年目、日本語まだ勉強中なので、文法上おかしいところがあるように思います。
文法ミスや誤字がありましたらあらかじめご了承ください。:pray_tone1:
もちろん編集リクエストでご意見いただければと思います。

参考リンク

https://www.itmedia.co.jp/help/tips/linux/l0052.html
https://nodejs.org/en/download/
https://gist.github.com/nrollr/325e9bc4c35a0523d290b38cfa3c5142
https://stackoverflow.com/questions/55031954/unicorn-refreshing-gem-list

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