Mac Book Pro (M1 Pro)安装 Ruby 2.2.0 遇到的问题

1. 安装 openssl 1.0

1
2
3
$ cd ~/tmp
$ curl -Lo openssl@1.0.rb https://raw.githubusercontent.com/rbenv/homebrew-tap/e472b7861b49cc082d1db0f66f265368da107589/Formula/openssl%401.0.rb
$ brew install ./openssl@1.0.rb

2. rbenv 安装 2.2.0

1
2
3
$ brew --prefix openssl@1.0
/opt/homebrew/opt/openssl@1.0
$ CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/openssl@1.0" rbenv install 2.2.0

会遇到下面的错误

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
Downloading ruby-2.2.0.tar.bz2...
-> https://cache.ruby-china.com/pub/ruby/2.2/ruby-2.2.0.tar.bz2
Installing ruby-2.2.0...

WARNING: ruby-2.2.0 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew

BUILD FAILED (macOS 12.0 using ruby-build 20211019)

Inspect or clean up the working tree at /var/folders/3y/5k7bvzg94b50d250zfzxxjqr0000gn/T/ruby-build.20211027143056.14917.1CNSu3
Results logged to /var/folders/3y/5k7bvzg94b50d250zfzxxjqr0000gn/T/ruby-build.20211027143056.14917.log

Last 10 log lines:
    0.00% documented

  Elapsed: 0.0s

config.status: creating -darwin21-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin21-fake.rb
make: *** [-darwin21-fake.rb] Error 64

解决方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ cd /var/folders/3y/5k7bvzg94b50d250zfzxxjqr0000gn/T/ruby-build.20211027143056.14917.1CNSu3/ruby-2.2.0/

$ vim config.status

# 找到下面的代码(1097行)

*) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file"

# 改成,将 rm -rf "$ac_file" 去掉

*) mv "$ac_tmp/out" "$ac_file";;

# 再编译 2.2.0 安装成功
$ make && make install

3. 安装 nokogiri 遇到的问题

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
This could take a while...
ERROR:  Error installing nokogiri:
  ERROR: Failed to build gem native extension.

    /Users/grant/.rbenv/versions/2.2.0/bin/ruby -r ./siteconf20211027-40423-oo5tbo.rb extconf.rb --with-iconv-dir=/opt/homebrew/opt/libiconv
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
-----
*** 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=/Users/grant/.rbenv/versions/2.2.0/bin/$(RUBY_BASE_NAME)
  --help
  --clean
  --use-system-libraries
  --enable-static
  --disable-static
  --with-zlib-dir
  --without-zlib-dir
  --with-zlib-include
  --without-zlib-include=${zlib-dir}/include
  --with-zlib-lib
  --without-zlib-lib=${zlib-dir}/lib
  --enable-cross-build
  --disable-cross-build

extconf failed, exit code 1

Gem files will remain installed in /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2 for inspection.

解决方法

1
gem install nokogiri:1.6.6.2 -- --use-system-libraries

4. 启动 rails 遇到的问题

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
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:84:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
Backtrace for gem load error is:
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/execjs-2.6.0/lib/execjs/runtimes.rb:48:in `autodetect'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/execjs-2.6.0/lib/execjs.rb:5:in `<module:ExecJS>'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/execjs-2.6.0/lib/execjs.rb:4:in `<top (required)>'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/uglifier-2.7.2/lib/uglifier.rb:3:in `require'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/uglifier-2.7.2/lib/uglifier.rb:3:in `<top (required)>'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:81:in `require'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:76:in `each'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:76:in `block in require'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:65:in `each'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:65:in `require'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler.rb:114:in `require'
/Users/grant/projects/launchapp/config/application.rb:8:in `<top (required)>'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `require'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `block in server'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
/Users/grant/projects/launchapp/bin/rails:8:in `require'
/Users/grant/projects/launchapp/bin/rails:8:in `<top (required)>'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/rails.rb:28:in `load'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/rails.rb:28:in `call'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/command.rb:7:in `call'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client.rb:28:in `run'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/bin/spring:49:in `<top (required)>'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/binstub.rb:11:in `load'
/Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/grant/projects/launchapp/bin/spring:13:in `require'
/Users/grant/projects/launchapp/bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Bundler Error Backtrace:
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:80:in `block (2 levels) in require'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:76:in `each'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:76:in `block in require'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:65:in `each'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler/runtime.rb:65:in `require'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.16.2/lib/bundler.rb:114:in `require'
 from /Users/grant/projects/launchapp/config/application.rb:8:in `<top (required)>'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `require'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `block in server'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
  from /Users/grant/projects/launchapp/bin/rails:8:in `require'
 from /Users/grant/projects/launchapp/bin/rails:8:in `<top (required)>'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/rails.rb:28:in `load'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/rails.rb:28:in `call'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client/command.rb:7:in `call'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/client.rb:28:in `run'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/bin/spring:49:in `<top (required)>'
 from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/binstub.rb:11:in `load'
  from /Users/grant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/binstub.rb:11:in `<top (required)>'
 from /Users/grant/projects/launchapp/bin/spring:13:in `require'
  from /Users/grant/projects/launchapp/bin/spring:13:in `<top (required)>'
 from bin/rails:3:in `load'
  from bin/rails:3:in `<main>'

解决方法

1
brew install node

5. postgres 连接出错

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
ActiveRecord::StatementInvalid (PG::InvalidParameterValue: ERROR:  invalid value for parameter "client_min_messages": "panic"
HINT:  Available values: debug5, debug4, debug3, debug2, debug1, log, notice, warning, error.
: SET client_min_messages TO 'panic'):
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:466:in `block in log'
  activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract_adapter.rb:460:in `log'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql/schema_statements.rb:275:in `client_min_messages='
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:313:in `set_standard_conforming_strings'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:677:in `configure_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:658:in `connect'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
  activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
  /Users/grant/.rbenv/versions/2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
  /Users/grant/.rbenv/versions/2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
  activerecord (4.2.0) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
  activerecord (4.2.0) lib/active_record/connection_handling.rb:87:in `connection'
  activerecord (4.2.0) lib/active_record/migration.rb:384:in `connection'
  activerecord (4.2.0) lib/active_record/migration.rb:371:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.0) lib/rails/engine.rb:518:in `call'
  railties (4.2.0) lib/rails/application.rb:164:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /Users/grant/.rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /Users/grant/.rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /Users/grant/.rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

解决方法

1
2
# postgres 12.0 版本太新,不兼容,安装旧版本
$ brew install postgresql@9.5

评论