天道酬勤,学无止境

Use rvmrc or ruby-version file to set a project gemset with RVM?

I use RVM, the Ruby Version Manager to specify a Ruby version and a set of gems for each of my Rails projects.

I have a .rvmrc file to automatically select a Ruby version and gemset whenever I cd into a project directory.

After installing RVM 1.19.0, I get a message

You are using .rvmrc, it requires trusting, it is slower and it is not compatible with other ruby managers, you can switch to .ruby-version using rvm rvmrc to [.]ruby-version or ignore this warnings with rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc, .rvmrc will continue to be the default project file in RVM 1 and RVM 2, to ignore the warning for all files run rvm rvmrc warning ignore all.rvmrcs.

Should I continue using my .rvmrc file or should I switch to a .ruby-version file? Which is optimal? What are the ramifications?

评论

If your .rvmrc file contains custom shell code, continue using .rvmrc as it allows you to include any shell code.

If your only aim is to switch Ruby versions, then use .ruby-version which is supported by other Ruby version switchers such as rbenv or chruby. This file also does not require trusting as it is just the name of a Ruby version and will not be executed in any way.

If you use .ruby-version you can include @gemset in the file but this will not be compatible with other switchers. To maintain compatibility use the gemset name in a separate file .ruby-gemset which is ignored by other tools (it works only together with .ruby-version).

For example, if you have a simple .rvmrc:

rvm use 1.9.3@my-app

It can be transformed to .ruby-version:

1.9.3

And .ruby-gemset:

my-app

Be sure to remove the .rvmrc file as it takes precedence over any other project configuration files:

rm .rvmrc

Quick and easy way to switch from .rvmrc to .ruby-version + .ruby-gemset

rvm rvmrc to .ruby-version

If you want create the .ruby-version and .ruby-gemset file in a short way you can use the commands like this:

rvm use 2.1.1@nancy --create

rvm --create --ruby-version 2.1.1@nancy

You can try both. Go to the root of your project, create a .rvmrc file (touch .rvmrc), then edit rvm use 2.0.0-p451@your_gemset (your ruby version and gemset name). After save this file, you can type this command:

cd ../your_project (you're in your_project directory), and the script in .rvmrc will execute.

The RVM recommend to use ruby-version. You can run this command to switch from .rvmrc to .ruby-version

rvm rvmrc to .ruby-version

What it does is create 2 files name .ruby-version, and .ruby-gemset and add this line

ruby-2.0.0-p451 in .ruby-version

your_gemset in .ruby-gemset

You can try to do it manually if you want :)

Install rvm using:

\curl -sSL https://get.rvm.io | bash -s stable --rails

Install different ruby versions:

rvm install 1.8.7
rvm install 1.9.2

Switch to specific ruby version. For example, 1.8.7:

rvm use 1.8.7

To create a gemse:

rvm gemset create project_gemset

And to use a gemset:

rvm gemset use project_gemset

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • How to fix “Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0”(How to fix “Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0”)
    问题 我创建了一个Ruby项目,但是在运行bundle update和bundle install它返回错误: Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0 它的图片是:http://i.imgur.com/dZMhI11.png?1 我的gemfile是: ruby '2.0.0' #ruby-gemset=railstutorial_rails_4_0 gem 'rails', '4.0.0' group :development do gem 'sqlite3', '1.3.8' end gem 'sass-rails', '4.0.0' gem 'uglifier', '2.1.1' gem 'coffee-rails', '4.0.0' gem 'jquery-rails', '3.0.4' gem 'turbolinks', '1.1.1' gem 'jbuilder', '1.0.2' group :doc do gem 'sdoc', '0.3.20', require: false end 回答1 如果运行ruby -v您将看到已经安装了Ruby 1.9.3,但是Gemfile中的第一行指定您要使用Ruby 2.0.0。 您应该安装Ruby 2.0
  • 您的Ruby版本是2.0.0,但是您的Gemfile指定了2.1.0(Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0)
    问题 当我尝试捆绑安装时,出现以下消息: Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0 在我的Gemfile中,我具有以下内容: ruby '2.1.0' 当我在控制台中运行ruby -v时,我得到: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0] Ruby 2.1.0p0是什么意思? 我的Gemfile中应该具有哪个版本,为什么该错误告诉我我具有Ruby 2.0.0版本? 回答1 跑 gem install bundler 或者 gem update bundler 这可能会解决您的问题。 对于所有新安装的Ruby版本,您应该更新或安装新的捆绑程序。 回答2 在项目的顶级目录中,创建一个名为.ruby-version的文件,其中包含(等待它... ) 2.1.0 显然,这是现在指定版本的交叉{rbenv,rvm}方法。 回答3 如果您在Rails项目中获得此功能,并且最近升级了Ruby版本,则您的Spring可能仍与旧版本的Ruby一起运行。 ./bin/spring stop 将解决此问题。 回答4 对我而言,所有答案都无济于事。 我固定了它,然后关闭并再次打开终端。 回答5 没有其他建议对我有用。 在服务器上,我必须执行以下操作
  • getaddrinfo: nodename nor servname provided, or not known
    I have a Ruby on Rails application that I am deploying on a computer running Mac OS X 10.6. The code where the problem arises is run by a delayed_job. The problem only occurs when it is run through delayed_job. If I run it within a console (rails console production) or call the API directly through cURL, it works without any problems. Also, the entire process works without issue in my development environment. Basically, the code works in one place, but for some reason, fails where it has to work. I've searched and found a few resources, but none of the suggestions apply or make any difference
  • centos7 redis requires Ruby version -= 2.2.2 问题解决
    出现的问题:[root@localhost ~]# gem install redisFetching: redis-4.0.1.gem (100%)ERROR: Error installing redis:redis requires Ruby version >= 2.2.2.<br> 原因:ruby版本太低,要求2.2.2版本+解决:安装rbuy高版本需要用rvm 来安装ruby [root@localhost ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 gpg: keyring `/root/.gnupg/secring.gpg' created gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported gpg: no ultimately trusted keys found gpg: Total
  • Rails keeps telling me that it's not currently installed
    I use rvm to manage different rubies and their gemsets. My shell is zsh with oh-my-zsh configured with basic settings. Enabled oh-my-zsh plugins are ruby, rails, osx, and git. Here's the command I used to install ruby-1.8.7 and rails-3.0.7. rvm install 1.8.7 rvm use 1.8.7 gem install rails -v=3.0.7 and then I typed rails and got: 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. I've tried more thorough installs also, Like reinstall rubygems after switching to ruby-1.8.7, or create a
  • find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
    I used sudo bundle install and that might be the cause of the issue? Now I have: gem -v 2.6.14 ruby -v ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin15] jekyll -v jekyll 3.6.2 bundle -vBundler version 1.16.0.pre.3 I'm getting the following error when trying to run bundle exec jekyll serve or just jekyll serve /Users/myusername/.rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) from /Users/myusername/.rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems.rb:299:in `activate_bin_path'
  • Why can't I install Rails on Lion using RVM?
    I'm running into issues trying to install Rails on OS X Lion using RVM. So far, I have done the following: Installed Mac OS X Lion Version 10.7 (Build 11A459e). Installed XCode 4.1 Developer Preview 5. Installed RVM. Installed a 1.8.7 version of Ruby via RVM using the command rvm install 1.8.7. Note: I need to be using 1.8.7 and not 1.9.2. Switched to the 1.8.7 version of Ruby using the command rvm 1.8.7. Created a new gemset using the command rvm gemset create rails3. Switched to the new gemset using the command rvm use 1.8.7@rails3. To install Rails I ran the command gem install rails but I
  • 未加载库:尝试在具有MySQL2的OS X 10.6上运行“ Rails服务器”时,libmysqlclient.16.dylib错误(Library not loaded: libmysqlclient.16.dylib error when trying to run 'rails server' on OS X 10.6 with mysql2 gem)
    问题 我已经为此苦苦挣扎了一段时间。 我已经在Snow Leopard机器上安装了Rails 3,gem,mysql。 一切顺利,直到我创建了我的第一个项目并尝试运行 rails server 运行此后,我得到: jontybrook$ rails server /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError) Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7 from /Library/Ruby/Gems/1.8
  • rbenv不更改Ruby版本(rbenv not changing ruby version)
    问题 我根据github的指示安装了rbenv。 我正在运行OSX,但是我已经在Ubuntu 12.04 VM上进行了尝试,并得到了相同的结果。 以下是我尝试更改红宝石版本时在终端中得到的内容: rbenv versions * 1.9.3-p0 (set by /Users/user/.rbenv/version) 1.9.3-p125 rbenv global 1.9.3-p0 rbenv rehash ruby -v ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0] which ruby /usr/bin/ruby 关于rbenv为什么不像它认为的那样切换ruby版本,有人有任何想法吗? 另外,本地目录中没有.rbenv文件,这将导致ruby版本默认为1.8.7。 rbenv local rbenv: no local version configured for this directory 回答1 检查PATH是否包含$HOME/.rbenv/shims和$HOME/.rbenv/bin $ env | grep PATH 如果使用bash,也请检查〜/ .bash_profile中是否包含以下内容;如果使用zsh,请检查〜/ .zshenv中是否包含以下内容: export PATH="$HOME
  • How do I use RVM and create globally available gems?
    I'm running Mac OSX 10.6.4 and have installed RVM. Its been great so far, I really love the way it lets me manage having multiple versions of rails and ruby on the same machine without headaches! However, I don't want to have to install certain gems (such as passenger) for each setup. Is there a way to share gems between gemsets? I have a 1.8.7@rails2.3.8 and 1.9.2@rails3, can I have gems such as passenger, mysql, and capistrano installed once and used with all versions?
  • redis数据导入导出
    在2017年,项目上的redis集群需要从2.8版本更换为3.2版本,此时涉及到redis数据key的迁移,经百度、×××,发现有三种方法可以实现1、第三方工具redis-dump、redis-load实现2、通过aof机制导入导出,需要开启aof功能3、通过rdb存储机制迁移数据,此方法最为简单,直接dump $key、restore $key即可 此篇主要介绍第一种方式,redis-dump、redis-load实现redis的数据导入导出,直接进入主题 redis-dump,要求ruby版本>=2.2.2 第一步:安装依赖的服务包(gcc服务包可用CentOS自带源即可) yum install ruby rubygems ruby-devel gcc -y 第二步:配置ruby官网源 gem sources -a http://gems.ruby-china.org/ ##将国内的源添加至本地,国内已将.org改为.com gem source -l ##查看ruby源 gem source --remove http://rubygems.org/ ##去掉对外源,如果使用rubygems源需××× gem source -l ##核实ruby源 第三步:gem安装redis-dump gem install redis-dump -V ##redis-dump
  • Error to install Nokogiri on OSX 10.9 Maverick?
    I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects. I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems. The error is: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb checking for libxml/parser.h... *** 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
  • SSL错误安装rubygems时,无法从'https://rubygems.org/提取数据(SSL Error When installing rubygems, Unable to pull data from 'https://rubygems.org/)
    问题 我正在尝试做Michael Hartl教程。 当我尝试在我的gemset中安装rails 3.2.14时,出现以下问题: $ gem安装导轨-v 3.2.14 错误:找不到有效的gem'rails'(= 3.2.14),这是原因: 无法从https://rubygems.org/下载数据-SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败(https://s3.amazonaws.com/production.s3.rubygems.org /specs.4.8.gz) 谷歌搜索之后,我发现我可以将非SSL来源用于rubygems,因此我运行了: sudo gem sources -a http://rubygems.org 然后,当我尝试再次安装滑轨时,它成功了。 但是,我仍然收到上述问题,但只是警告: 警告:无法从“ https://rubygems.org/”提取数据:SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败(https://s3.amazonaws.com/production.s3 .rubygems.org / specs.4.8.gz) 如何完全删除此警告/错误? 我正在使用以下内容: rvm 1.22.15 红宝石2.0.0p247(2013-06
  • Curl Certificate Error when Using RVM to install Ruby 1.9.2
    RVM is running into a certificate error when trying to download Ruby 1.9.2. It looks like curl is having a certificate issue but I am not sure how to bypass it. I have included the exact error info below. $ rvm install 1.9.2 Installing Ruby from source to: /Users/willdennis/.rvm/rubies/ruby-1.9.2-p180, this may take a while depending on your cpu(s)... ruby-1.9.2-p180 - #fetching ERROR: Error running 'bunzip2 '/Users/willdennis/.rvm/archives/ruby-1.9.2-p180.tar.bz2'', please read /Users/willdennis/.rvm/log/ruby-1.9.2-p180/extract.log ruby-1.9.2-p180 - #extracting ruby-1.9.2-p180 to /Users
  • SSL Error When installing rubygems, Unable to pull data from 'https://rubygems.org/
    I am trying to do the Michael Hartl tutorial. When I attempt to install rails 3.2.14 in my gemset, I get the following issue: $ gem install rails -v 3.2.14 ERROR: Could not find a valid gem 'rails' (= 3.2.14), here is why: Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://s3.amazonaws.com/production.s3.rubygems.org/specs.4.8.gz) After Googling around, I found that I could use a non-SSL source for rubygems so I ran: sudo gem sources -a http://rubygems.org Then, when I tried to install
  • Using Python with homebrew on OS X
    I have been using Mac python for a while, and I decided to teach myself matplotlib, because I want to have the experience with some common modules. I hear from everyone that once you get into non-standard modules, it's best to use python threw homebrew, so you have access to pip and not easy_install. After running: $brew install python --with-brewed-openssl, $brew install python3 --with-brewed-openssl, and $pip install matplotlib, I go to the python shell with $python3. Once there, I run import matplotlib.pyplot as plt, and get the following: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00
  • ERROR: Failed to build gem native extension on Mavericks
    I'm attempting to run bundle in my Rails project on OSX 10.9. It fails when getting to the pg gem with this error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for pg_config_manual.h... yes checking for PQconnectdb() in -lpq... yes checking for PQconnectionUsedPassword()... yes
  • “gem install rails” fails with DNS error
    $ rvm use Using /home/owner/.rvm/gems/ruby-2.1.2 $ gem install rails ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) Errno::ECONNREFUSED: Connection refused - connect(2) for "your-dns-needs-immediate-attention.network" port 80 (http://your-dns-needs-immediate-attention.network/quick/Marshal.4.8/thread_safe-0.3.4.gemspec.rz) $ gem update --system ... $ gem -v 2.4.1 $ gem install rails ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) Errno::ECONNREFUSED: Connection refused - connect(2) for "your-dns-needs-immediate-attention.network" port 80 (http://your-dns-needs
  • How to turn off w3c in chromedriver to address the error unknown command: Cannot call non W3C standard command while in W3C
    With version 75 of Chrome just released, our tests no longer run properly. They give the stacktrace pasted below. We are using ruby on rails v. 5.1.6.2 with rspec, selenium-webdriver 3.8.0. Stacktrace: Selenium::WebDriver::Error::UnknownCommandError: unknown command: Cannot call non W3C standard command while in W3C mode # 0 chromedriver 0x000000010c46e8e9 chromedriver + 3594473 # 1 chromedriver 0x000000010c3fe543 chromedriver + 3134787 # 2 chromedriver 0x000000010c1aa29f chromedriver + 692895 # 3 chromedriver 0x000000010c11a691 chromedriver + 104081 # 4 chromedriver 0x000000010c11b7d5
  • Installing libv8 gem on OS X 10.9+
    I'm trying to install libv8 3.16.14.3 but getting an error on OSX Mavericks using latest stable rvm and ruby-1.9.3-p125. This is the output of running the command 'gem install libv8': ~/src(branch:master) » gem install libv8 Fetching: libv8-3.16.14.3.gem (100%) Building native extensions. This could take a while... ERROR: Error installing therubyracer: ERROR: Failed to build gem native extension. /Users/me/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb creating Makefile Compiling v8 for x64 Using python 2.7.5 Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx