爪を切る頻度が高いmizkyです。
rails newして新規プロジェクトを作成した際のエラーについて書きます。
Make sure that gem install sassc -v '2.4.0' --source 'https://rubygems.org/'
error: unrecognized command line option “-std=c++11”
のようなエラーが出ている方のお助けになれば幸いです。
実行環境
仮想環境のCentOS6となります。
エラー内容
rails newで新規プロジェクトを作成しようとすると以下のエラーが発生しました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [vagrant@localhost]$railsnewmyapp Anerroroccurredwhileinstallingsassc(2.4.0),andBundlercannotcontinue. Makesurethat`geminstallsassc-v'2.4.0'--source'https://rubygems.org/'`succeedsbefor InGemfile: sass-railswasresolvedto6.0.0,whichdependson sassc-railswasresolvedto2.1.2,whichdependson sassc run bundlebinstubsbundler Couldnotfindgem'sass-rails (>= 6)'inanyofthegemsourceslistedinyourGemfile. run bundleexecspringbinstub--all bundler:commandnotfound:spring Installmissinggemexecutableswith`bundleinstall` rails webpacker:install Couldnotfindgem'sass-rails (>= 6)'inanyofthegemsourceslistedinyourGemfile. Run`bundleinstall`toinstallmissinggems. |
うっわ。泣きそう。
3行目に
Make sure that gem install sassc -v '2.4.0' --source 'https://rubygems.org/'
succeeds
と書いてあるので素直に従ってみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [vagrant@localhost]$geminstallsassc-v'2.4.0'--source'https://rubygems.org/' Buildingnativeextensions.Thiscouldtakeawhile... ERROR: Errorinstallingsassc: ERROR:Failedtobuildgemnativeextension. currentdirectory:/home/vagrant/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sassc-2.4.0/ext /home/vagrant/.rbenv/versions/2.5.8/bin/ruby-I/home/vagrant/.rbenv/versions/2.5.8/lib/ruby/ site_ruby/2.5.0-r./siteconf20201010-3745-xg8z0u.rbextconf.rb creatingMakefile currentdirectory:/home/vagrant/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sassc-2.4.0/ext make"DESTDIR="clean currentdirectory:/home/vagrant/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sassc-2.4.0/ext make"DESTDIR=" compiling./libsass/src/ast.cpp cc1plus:error:unrecognizedcommandlineoption"-std=c++11" make:***[ast.o]エラー1 makefailed,exitcode2 Gemfileswillremaininstalledin/home/vagrant/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/sassc-2.4.0forinspection. Resultsloggedto/home/vagrant/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0/sassc-2.4.0/gem_make.out |
これ見た瞬間帰りたくなった。
ちなみに自宅で作業してたから、どこに帰るんだよって話。
解決策
肝心なのは以下の行になります。
cc1plus: error: unrecognized command line option “-std=c++11”
どうやらGCCのバージョンが古い可能性があるので、バージョンをあげてみます。
最初に、現在使用しているGCCのバージョンを確認します。
1 2 | $gcc--version|head-n1 gcc(GCC)4.4.720120313(RedHat4.4.7-23) |
バージョンが4ということなので7まであげます。
1 2 | $sudoyuminstalldevtoolset-7 $sclenabledevtoolset-7bash |
再度、GCCのバージョンを確認します
1 2 | $gcc--version|head-n1 gcc(GCC)7.3.120180303(RedHat7.3.1-5) |
以下に、GCCのバージョンをあげる際に参考にしたURLを掲載します。
これで
1 | geminstallsassc-v'2.4.0'--source'https://rubygems.org/' |
をすると上手くいきました。
エラーの原因
CentOS6だとGCCのバージョンが非常に古いようです。
CentOS8が出てる時代だもんな・・・
後書き
Railsでプロジェクトを全く1から作成したことがなかったので、今回自分で行ったところ、本記事のエラーに遭遇しました。
間もないプログラム初心者がRails始めよおおお!!と思って取り組んだ結果、こんなエラー出たら秒で投げ出しますよね・・・
そもそもプログラム初心者がRailsやんのかよって話もありますがwww
プログラムってプログラム書くところじゃなくて環境構築とかテストなどが原因で始めようと思ったけど挫折する人が多いのではと思った1日でした。

「mizky」で「みずき」と読みます。エンターテイナーになりたい。普段はサラリーマン(気持ちは引き篭もりニート)。アプリ開発、HP運営、投資など手広くやっております。九州大学大学院卒業。趣味は旅行、レースゲーム。
コメント