TermuxからRailsインストール、そしてnokogiriとsasscでエラー(解決)
TermuxでのRailsインストールの手順をまとめてみた。
試行錯誤でやっていたので、まっさらな状態でできるかがあやしいが、以下でインストールできると思う。本当は一発でrails newしたかったが無理そう。なお、MySQLを使用しない場合は「-d mysql」を外す。SQLiteを使わなければpkgから「sqlite libsqlite」を外す。
pkg update pkg install ruby clang make pkg-config libxslt sqlite libsqlite zlib libiconv libxml2 git wget nodejs yarn python2 binutils gem install nokogiri -- --use-system-libraries gem install sassc -- --disable-march-tune-native gem install rails wget https://github.com/termux/termux-packages/files/2912002/fix-ruby-bigdecimal.sh.txt bash fix-ruby-bigdecimal.sh.txt gem install spring gem install tzinfo-data rails new ./HogeHoge -d mysql # Gemfileの問題で必ず「TZInfo::DataSourceNotFound: tzinfo-data is not present.」で停止。 cd HogeHoge vi Gemfile # Gemfileの「gem 'tzinfo-data'」の後ろのplatformsを削除。行削除ではダメ。 bundle update cd .. yes n | rails new ./HogeHoge -d mysql
Gemini PDAを初期化して、以前書いた記事を参考にまたもやTermuxからRailsをインストール。
Rooted AndroidにTermuxを入れてRailsをインストール - etsuxのブログ
nokogiriのエラー
そしてnokogiriでエラー。単品でgemしてみてももちろんエラー。
$ gem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. current directory: /data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/nokogiri-1.10.8/ext/nokogiri /data/data/com.termux/files/usr/bin/ruby -I /data/data/com.termux/files/usr/lib/ruby/2.6.0 -r ./siteconf20200215-5692-1lambql.rb extconf.rb checking if the C compiler accepts ... yes Building nokogiri using packaged libraries. Using mini_portile version 2.4.0 checking for gzdopen() in -lz... yes checking for iconv... yes ************************************************************************ IMPORTANT NOTICE: Building Nokogiri with a packaged version of libxml2-2.9.10 with the following patches applied: - 0001-Revert-Do-not-URI-escape-in-server-side-includes.patch - 0002-Remove-script-macro-support.patch - 0003-Update-entities-to-remove-handling-of-ssi.patch - 0004-libxml2.la-is-in-top_builddir.patch - 0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch Team Nokogiri will keep on doing their best to provide security updates in a timely manner, but if this is a concern for you and want to use the system library instead; abort this installation process and reinstall nokogiri as follows: gem install nokogiri -- --use-system-libraries [--with-xml2-config=/path/to/xml2-config] [--with-xslt-config=/path/to/xslt-config] If you are using Bundler, tell it to use the option: bundle config build.nokogiri --use-system-libraries bundle install Note, however, that nokogiri is not fully compatible with arbitrary versions of libxml2 provided by OS/package vendors. ************************************************************************ Extracting libxml2-2.9.10.tar.gz into tmp/aarch64-linux-android/ports/libxml2/2.9.10... ERROR, review '/data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/ nokogiri-1.10.8/ext/nokogiri/tmp/aarch64-linux-android/ports/libxml2/2.9.10/extract.log' to see what happened. Last lines are: ======================================================================== tar: libxml2-2.9.10/test/relaxng/ambig_name-class2.rng: Cannot hard link to ‘libxml2-2.9.10/test/relaxng/ambig_name-class.xml’: Permission denied tar: libxml2-2.9.10/test/relaxng/ambig_name-class.rng: Cannot hard link to ‘libxml2-2.9.10/test/relaxng/tutorA.rng’: Permission denied tar: Exiting with failure status due to previous errors ======================================================================== *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
いろいろなサイトでいろいろなことが載っていて、いろいろ試してもダメだった。
nokogiriのエラーの解決方法
仕方なく、鋸のサイトを見てみると...あ~載っている。
Installing Nokogiri - Nokogiri
TermUX
Although TermUX isn't fully supported right now, some people have reported success getting Nokogiri installed on it by running these commands:
これに従ってコマンドを打つ。
$ pkg install ruby clang make pkg-config libxslt : clang is already the newest version (9.0.1). make is already the newest version (4.3-1). ruby is already the newest version (2.6.5). The following additional packages will be installed: glib The following NEW packages will be installed: glib libxslt pkg-config 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 1348 kB of archives. After this operation, 8208 kB of additional disk space will be used. Do you want to continue? [Y/n] Y : $ gem install nokogiri -- --use-system-libraries Building native extensions with: '--use-system-libraries' This could take a while... Successfully installed nokogiri-1.10.8 Parsing documentation for nokogiri-1.10.8 Installing ri documentation for nokogiri-1.10.8 Done installing documentation for nokogiri after 89 seconds 1 gem installed
本家を見に行かず、すみません。
sasscのエラー
次はsasscのエラー。ARMのclangでは'-march=native'がサポートされていない?
ちなみに実際には「rails new」で作成しようとした際にエラーとなった。
$ gem install sassc Building native extensions. This could take a while... ERROR: Error installing sassc: ERROR: Failed to build gem native extension. current directory: /data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/sassc-2.2.1/ext /data/data/com.termux/files/usr/bin/ruby -I /data/data/com.termux/files/usr/lib/ruby/2.6.0 -r ./siteconf20200215-11591-1ve0vft.rb extconf.rb creating Makefile current directory: /data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/sassc-2.2.1/ext make "DESTDIR=" clean current directory: /data/data/com.termux/files/usr/lib/ruby/gems/2.6.0/gems/sassc-2.2.1/ext make "DESTDIR=" compiling ./libsass/src/ast.cpp clang-9: error: the clang compiler does not support '-march=native' make: *** [Makefile:237: ast.o] Error 1 make failed, exit code 2
extconf.rbの中身を見ると、march-tune-nativeをfalseにすれば出力されないことがわかる。
# Set to false when building binary gems if enable_config('march-tune-native', true) $CFLAGS << ' -march=native -mtune=native' $CXXFLAGS << ' -march=native -mtune=native' end
sasscのエラーの解決方法
「--disable-march-tune-native」をつけてgemしてみたところ正常終了。
$ gem install sassc -- --disable-march-tune-native Building native extensions with: '--disable-march-tune-native' This could take a while... Successfully installed sassc-2.2.1 Parsing documentation for sassc-2.2.1 Installing ri documentation for sassc-2.2.1 Done installing documentation for sassc after 70 seconds 1 gem installed
別のエラーで、stripコマンドがないと言われることがある。その場合はbinutilsパッケージをインストールする。
make: strip: No such file or directory
railsをインストール
$ gem install rails : Done installing documentation for crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 660 seconds 30 gems installed
rails newしてみる
順に解決を試みていく。
$ rails new ./HogeHoge -d mysql : The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. : clang-9: error: the clang compiler does not support '-march=native' → (1)解決 : run bundle exec spring binstub --all bundler: command not found: spring → (2)解決 : LoadError: dlopen failed: cannot locate symbol "rmpd_util_str_to_d" referenced by "/data/data/com.termux/files/usr/lib/ruby/2.6.0/aarch64-linux-android/bigdecim al/util.so"... - /data/data/com.termux/files/usr/lib/ruby/2.6.0/aarch64-linux-android/bigdecimal/util.so → (3)解決 : rails webpacker:install sh: 1: node: not found sh: 1: nodejs: not found Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/ → (4)解決 : rails aborted! TZInfo::DataSourceNotFound: tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install → (5)解決 /data/data/com.termux/files/home/rails/HogeHoge/config/environment.rb:5:in `
- (1)は上記に対処を記載済。
- (2)はGemfileの「group :development」のみに「gem 'spring'」があるから?system側に入れてしまえばエラーにはならないけど。
$ gem install spring Successfully installed spring-2.1.0 Parsing documentation for spring-2.1.0 Installing ri documentation for spring-2.1.0 Done installing documentation for spring after 2 seconds 1 gem installed $ cd HogeHoge/ $ bundle exec spring binstub --all * bin/rake: Spring inserted * bin/rails: Spring inserted
- (3)は以前の記事で書いていた。
rails db:migrateのエラー(rmpd_util_str_to_dとlibexslt.so) - etsuxのブログ
- (4)はnodejsとその依存のyarnの不足。
pkg install nodejs yarn
- (5)はGemfileの'tzinfo-data'のplatformsを削除。
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
ちなみに、platformは"aarch64-linux-android"だけど、platformsには指定できない。$ ruby -e "p RUBY_PLATFORM" "aarch64-linux-android"
rails webpacker:installのエラーは未調査
rails webpacker:installでエラーが出ているけど、python2がないことが原因。
[4/4] Building fresh packages... [-/2] ? waiting... error /data/data/com.termux/files/home/rails/HogeHoge/node_modules/node-sass: Command failed. Exit code: 1 Command: node scripts/build.js Arguments: Directory: /data/data/com.termux/files/home/rails/HogeHoge/node_modules/node-sass Output: Building: /data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/home/rails/HogeHoge/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --lib sass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= : gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` failed Error: not found: python2
python2をインストールしたが、以下のシンボル未解決が大量に出力されている。実行にも時間がかかるし。webpackerってプロジェクトごとにinstallされるものなの?
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: Release/obj.target/src/sass.a(base64vlq.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol ` _ZN4Sass9Base64VLQ10CHARACTERSE' which may bind externally can not be used when making a shared object; recompile with -fPIC Release/obj.target/src/sass.a(base64vlq.o): in function `Sass::Base64VLQ::base64_encode(int) const': base64vlq.cpp:(.text+0xa8): dangerous relocation: unsupported relocation clang-9: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [binding.target.mk:152: Release/obj.target/binding.node] Error 1 make: Leaving directory '/data/data/com.termux/files/home/rails/HogeHoge/node_modules/node-sass/build' gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2