mysql2をインストールしようとしてエラーが出た対応メモ

Ubuntu + Mysql5 + Rails3.2 に mysql2 をインストールしようとしてエラーが出た時の対処メモ。

環境

  • OS: Ubuntu 12.04 64bit
  • Ruby: ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
  • rvm: rvm 1.14.3 (stable)
  • Ruby on Rails: 3.2.6
  • Gem
    • mysql2 0.3.11

mysql2 をインストールしようとしてエラー

mysql2 をインストールするため Gemfile に追記します。

Gemfile
1
gem 'mysql2'

いつも通り bundle install を実行するとエラーが発生して mysql2 がインストール出来ません。

Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Installing mysql2 (0.3.11) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/home/nanigashi/.rvm/rubies/ruby-1.8.7-p358/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/nanigashi/.rvm/rubies/ruby-1.8.7-p358/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in /home/nanigashi/.rvm/gems/ruby-1.8.7-p358@hoge_rails3/gems/mysql2-0.3.11 for inspection.
Results logged to /home/nanigashi/.rvm/gems/ruby-1.8.7-p358@hoge_rails3/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occured while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.

必要なライブラリをインストール

調べたらライブラリが足りないとのことなのでインストールします。

Terminal
1
$ sudo aptitude install libmysql-ruby libmysqlclient-dev

再度 bundle install を実行すると無事入りました。

以上です。

terminator+tmuxでsshした先のvimを起動すると256色エラーが出る対応

Terminator + tmux を利用して ssh をした先で、vim を起動すると256色で表示されない対応メモ。
ちなみに、標準の端末では問題なく表示出来ました。

環境

  • OS: Ubuntu 12.04 64bit
  • Terminator 0.96
  • tmux 1.6-1

エラー内容

下記のエラーが出て256色にならない。

Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ ssh 111.222.333.444
$ vim

E558: Trerminal entry not found in terminfo
'screen-256color' not known. Available builtin terminals are:
builtin_riscos
builtin_amiga
builtin_beos-ansi
builtin_pcansi
builtin_win32
builtin_vt320
builtin_vt52
builtin_xterm
builtin_iris-ansi
builtin_debug
builtin_dumb
defaulting to 'ansi'

対応内容

いろいろ足らないみたいだが、screen上だと再現しないみたいなので、手っ取り早くsshの時はscreen接続で回避することにする。
.bashrcもしくは.zshrcなどに下記を追記。

Terminal
1
alias ssh='TERM=screen ssh'

読み込んだ後、再度sshして接続すれば大丈夫です。

以上です。

Rails3でデプロイ直後にアクセスで発生する Errno::EPERM エラー対応した

デプロイ直後にアクセスすると必ずエラーが発生するので対応。

環境

  • OS: CentOS release 5.5 (Final)
  • Ruby: ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
  • Ruby on Rails: 3.2.6

エラー内容

アクセスした時に発生。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Errno::EPERM in Hoge#index

Showing /var/www/hoge/releases/20120823092832/app/views/layouts/foo.html.erb where line #14 raised:

Operation not permitted - /var/www/hoge/releases/20120823092832/tmp/cache/assets/D4E/100/sprockets%2F3fc9cdaa37d24912e4d922964a95de96

Extracted source (around line #14):

11: <meta name="apple-mobile-web-app-capable" content="no" />
12: <title>タイトル</title>
13:
14: <%= stylesheet_link_tag 'jquery.mobile-1.0b1.min' %>
15: <%= stylesheet_link_tag 'bar' %>
16:

Trace of template inclusion: app/views/layouts/application.html.erb

Rails.root: /var/www/hoge/releases/20120823092832
Application Trace | Framework Trace | Full Trace

ちなみにログファイルには下記のように出力されてる。

1
2
3
4
5
6
7
8
ActionView::Template::Error (Operation not permitted - /var/www/hoge/releases/20120823092832/tmp/cache/assets/D4E/100/sprockets%2F3fc9cdaa37d24912e4d922964a95de96):

11: <meta name="apple-mobile-web-app-capable" content="no" />
12: <title>タイトル</title>
13:
14: <%= stylesheet_link_tag 'jquery.mobile-1.0b1.min' %>
15: <%= stylesheet_link_tag 'bar' %>
16:

原因

rake assets:precompile を実行した時にプリコンパイルされるスタイルシートから漏れているファイルを読み込もうとすると発生する。

通常は application.css.scss

application.css.scss
1
2
3
4
/*
*= require_self
*= require_tree .
*/

上記のように記述して結合したものを読み込むが、記述されていないファイルを読み込もうとしてしまっている。

解決方法

プリコンパイルされていないファイルを読み込んだ時にコンパイルするように

config/environments/production.rb
1
config.assets.compile = true

上記を追記してもいいが、初回のアクセス時にコンパイルするため時間がかかる。

なので、rake assets:precompile 実行時に結合しないファイルも一緒にプリコンパイルするように以下のように設定する。

config/environments/production.rb
1
config.assets.precompile = %w(hoge.css bar.css foo.css)

ちなみに Capistrano でデプロイ時に設定するには Capfile へ下記を追記。

Capfile
1
2
3
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets' # 追記

以上です。

© 2024 磁力式駆動 All Rights Reserved.
Theme by hiero