最近需要在同一台电脑上同时配置 JRuby on Rails,和 Ruby on Rails 但在 JRuby 下始终安装 Rails 不成功。过程如下: 之前在电脑上已经安装了 RVM 然后默认安装了 Ruby2.2.0 和 Rails4.2.0, 最近项目组需要研究下 JRuby 于是我从 JRuby 官网上下载了 zip 文件,解压后配置了环境变量, 通过下面的方法安装了 jruby,
rvm mount ~/jruby-1.7.19/bin/jruby
然后执行 rvm list
rvm rubies
ext-jruby-1.7.19 [ x86_64 ]
ext-q [ universal ]
=* ruby-2.2.0 [ x86_64 ]
这个时候执行 which rails 的位置信息如下:
MacBook-Pro:/neo $ which rails
/Users/neo/.rvm/gems/ruby-2.2.0/bin/rails
MacBook-Pro:/neo$ rails -v
Rails 4.2.0
切换到 JRuby 下面
MacBook-Pro:/ neo$ rvm use ext-jruby-1.7.19 --default
Using /Users/neo/.rvm/gems/ext-jruby-1.7.19
创建并使用一个新的 gemset
MacBook-Pro:/ neo$ rvm gemset create rails420
ext-jruby-1.7.19 - #gemset created /Users/neo/.rvm/gems/ext-jruby-1.7.19@rails420
ext-jruby-1.7.19 - #generating rails420 wrappers........
MacBook-Pro:/ neo$ rvm gemset use rails420
Using ext-jruby-1.7.19 with gemset rails420
安装 Rails
MacBook-Pro:/ neo$ gem install rails
Fetching: rails-4.2.0.gem (100%)
Successfully installed rails-4.2.0
1 gem installed
这个时候我就觉得很疑惑了,怀疑是不是之前因为网络中断造成某些缓冲还在,我记得 gem insall rails 会安装很多东西,但是这里只有一个,这个时候在执行 which rails , 指向的也是一个奇怪的地址,并且 rails -v 失败,我怀疑是不是什么地方弄错了。
MacBook-Pro:/ neo$ which rails
/usr/bin/rails
MacBook-Pro:/ neo$ rails -v
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
这个时候查看 gem list ,也没看出个问题,还望各位指点
MacBook-Pro:/ neo$ gem list
*** LOCAL GEMS ***
actionmailer (4.2.0)
actionpack (4.2.0)
actionview (4.2.0)
activejob (4.2.0)
activemodel (4.2.0)
activerecord (4.2.0)
activesupport (4.2.0)
arel (6.0.0)
axiom-types (0.1.1)
builder (3.2.2)
bundler (1.8.4)
coercible (1.0.0)
descendants_tracker (0.0.4)
equalizer (0.0.9)
erubis (2.7.0)
ffi (1.9.3 java)
gem-wrappers (1.2.7)
globalid (0.3.3)
hike (1.2.3)
i18n (0.7.0)
ice_nine (0.11.1)
jar-dependencies (0.1.2)
jruby-openssl (0.9.5 java)
json (1.8.0 java)
krypt (0.0.2)
krypt-core (0.0.2 universal-java)
krypt-provider-jdk (0.0.2)
loofah (2.0.1)
mail (2.6.3)
maven-tools (1.0.7)
mime-types (2.4.3)
minitest (5.5.1)
multi_json (1.11.0)
nokogiri (1.6.6.2 java)
rack (1.6.0)
rack-test (0.6.3)
rails (4.2.0)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.5)
rails-html-sanitizer (1.0.2)
railties (4.2.0)
rake (10.1.0)
rdoc (4.1.2)
ruby-maven (3.1.1.0.8)
ruby-maven-libs (3.1.1)
rvm (1.11.3.9)
sprockets (2.12.3)
sprockets-rails (2.2.4)
thor (0.19.1)
thread_safe (0.3.4 java)
tilt (1.4.1)
tzinfo (1.2.2)
virtus (1.0.4)
========================问题解决========================================
remove 掉 JRuby 以后重新安装 Jruby 然后再次 gem install rails,这一次安装成功,猜测是因为上次第一次 install rails 时,中途网络中断,造成了了一些什么问题
MBP:~ neo$ gem install rails
Fetching: minitest-5.5.1.gem (100%)
Successfully installed minitest-5.5.1
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: activesupport-4.2.0.gem (100%)
Successfully installed activesupport-4.2.0
Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
Successfully installed rails-deprecated_sanitizer-1.0.3
Fetching: nokogiri-1.6.6.2-java.gem (100%)
Successfully installed nokogiri-1.6.6.2-java
Fetching: rails-dom-testing-1.0.5.gem (100%)
Successfully installed rails-dom-testing-1.0.5
Fetching: loofah-2.0.1.gem (100%)
Successfully installed loofah-2.0.1
Fetching: rails-html-sanitizer-1.0.2.gem (100%)
Successfully installed rails-html-sanitizer-1.0.2
Fetching: erubis-2.7.0.gem (100%)
Successfully installed erubis-2.7.0
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: actionview-4.2.0.gem (100%)
Successfully installed actionview-4.2.0
Fetching: rack-1.6.0.gem (100%)
Successfully installed rack-1.6.0
Fetching: rack-test-0.6.3.gem (100%)
Successfully installed rack-test-0.6.3
Fetching: actionpack-4.2.0.gem (100%)
Successfully installed actionpack-4.2.0
Fetching: tilt-1.4.1.gem (100%)
Successfully installed tilt-1.4.1
Fetching: multi_json-1.11.0.gem (100%)
Successfully installed multi_json-1.11.0
Fetching: hike-1.2.3.gem (100%)
Successfully installed hike-1.2.3
Fetching: sprockets-2.12.3.gem (100%)
Successfully installed sprockets-2.12.3
Fetching: sprockets-rails-2.2.4.gem (100%)
Successfully installed sprockets-rails-2.2.4
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: railties-4.2.0.gem (100%)
Successfully installed railties-4.2.0
Fetching: globalid-0.3.3.gem (100%)
Successfully installed globalid-0.3.3
Fetching: activejob-4.2.0.gem (100%)
Successfully installed activejob-4.2.0
Fetching: mime-types-2.4.3.gem (100%)
Successfully installed mime-types-2.4.3
Fetching: mail-2.6.3.gem (100%)
Successfully installed mail-2.6.3
Fetching: actionmailer-4.2.0.gem (100%)
Successfully installed actionmailer-4.2.0
Fetching: arel-6.0.0.gem (100%)
Successfully installed arel-6.0.0
Fetching: activemodel-4.2.0.gem (100%)
Successfully installed activemodel-4.2.0
Fetching: activerecord-4.2.0.gem (100%)
Successfully installed activerecord-4.2.0
Fetching: rails-4.2.0.gem (100%)
Successfully installed rails-4.2.0
31 gems installed
MBP:~ neo$ which rails
/Users/neo/.rvm/gems/jruby-1.7.19/bin/rails
MBP:~ neo$ rails -v
Rails 4.2.0