天道酬勤,学无止境

使用rvmrc或ruby-version文件通过RVM设置项目gemset?(Use rvmrc or ruby-version file to set a project gemset with RVM?)

问题

我使用RVM,Ruby版本管理器为我的每个Rails项目指定一个Ruby版本和一组gem。

我有一个.rvmrc文件,可以在每次cd进入项目目录时自动选择Ruby版本和gemset。

安装RVM 1.19.0后,我收到一条消息

您正在使用.rvmrc ,它需要信任,速度较慢,并且与其他ruby管理器不兼容,您可以使用rvm rvmrc to [.]ruby-version切换到.ruby-version rvm rvmrc to [.]ruby-versionrvm rvmrc to [.]ruby-version或通过rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc忽略此警告rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc.rvmrc仍将是默认的项目文件中RVM 1和2 RVM,对所有文件运行忽略警告rvm rvmrc warning ignore all.rvmrcs

我应该继续使用.rvmrc文件还是应该切换到.ruby-version文件? 哪个是最佳的? 有哪些后果?

回答1

如果您的.rvmrc文件包含自定义外壳程序代码,请继续使用.rvmrc因为它允许您包含任何外壳程序代码。

如果您唯一的目的是切换Ruby版本,请使用.ruby-version ,该.ruby-version受其他Ruby版本切换器(例如rbenv或chruby)支持。 该文件也不需要信任,因为它只是Ruby版本的名称,不会以任何方式执行。

如果使用.ruby-version ,则可以在文件中包含@gemset ,但这与其他切换器不兼容。 为了保持兼容性,请在单独的文件.ruby-gemset使用gemset名称,该文件会被其他工具忽略(仅与.ruby-version一起使用)

例如,如果您有一个简单的.rvmrc

rvm use 1.9.3@my-app

可以将其转换为.ruby-version

1.9.3

.ruby-gemset

my-app

确保删除.rvmrc文件,因为它优先于任何其他项目配置文件:

rm .rvmrc
回答2

从.rvmrc切换到.ruby-version + .ruby-gemset的快速简便方法

rvm rvmrc to .ruby-version
回答3

如果要以简短方式创建.ruby-version.ruby-gemset文件,则可以使用以下命令:

rvm use 2.1.1@nancy --create

rvm --create --ruby-version 2.1.1@nancy
回答4

您可以同时尝试。 转到项目的根目录,创建一个.rvmrc文件( touch .rvmrc ),然后rvm use 2.0.0-p451@your_gemset (您的红宝石版本和gemset名称)编辑rvm use 2.0.0-p451@your_gemset 。 保存此文件后,可以键入以下命令:

cd ../your_project ../ your_project (您在your_project目录中),. rvmrc中的脚本将执行。

RVM建议使用ruby版本。 您可以运行此命令从.rvmrc切换到.ruby-version

rvm rvmrc to .ruby-version

它要做的是创建2个文件名为.ruby-version.ruby-gemset并添加此行

.ruby版本中的ruby-2.0.0-p451

your_gemset在.ruby,宝石

您可以尝试手动进行操作:)

回答5

使用以下命令安装rvm:

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

安装不同的ruby版本:

rvm install 1.8.7
rvm install 1.9.2

切换到特定的红宝石版本。 例如1.8.7:

rvm use 1.8.7

要创建宝石:

rvm gemset create project_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>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • 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
  • 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
  • How does RVM detect when you've changed directories?
    One thing that RVM can do is notice when you've changed directories, look for an .rvmrc, and change your current Ruby version and gemset according to that file's contents. It makes this change as soon as you change into that directory and outputs a message accordingly. How does it detect a change in the current working directory? I can imagine an extremely crude way of doing this: run a daemon that runs as the current user and keeps checking the results of pwd. But I'm sure that's not what it does. Another approach might be to alias cd to change directories but also check for an .rvmrc and
  • 您的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 没有其他建议对我有用。 在服务器上,我必须执行以下操作
  • 无法在带有RVM的Lion下安装Ruby – GCC问题(Can't install Ruby under Lion with RVM – GCC issues)
    问题 有关此问题的大多数问题是由于缺少Xcode造成的。 我已经安装了Xcode 4.2。 安装尝试: rvm install 1.9.3 Installing Ruby from source to: /Users/jamie/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)... ruby-1.9.3-p0 - #fetching ruby-1.9.3-p0 - #extracted to /Users/jamie/.rvm/src/ruby-1.9.3-p0 (already extracted) Fetching yaml-0.1.4.tar.gz to /Users/jamie/.rvm/archives Extracting yaml-0.1.4.tar.gz to /Users/jamie/.rvm/src Configuring yaml in /Users/jamie/.rvm/src/yaml-0.1.4. Compiling yaml in /Users/jamie/.rvm/src/yaml-0.1.4. Installing yaml to /Users/jamie/.rvm/usr ruby-1.9.3-p0 - #configuring ERROR
  • 未加载库:尝试在具有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
  • 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'
  • 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
  • 使用RVM安装了Ruby 1.9.3,但命令行未显示ruby -v(Installed Ruby 1.9.3 with RVM but command line doesn't show ruby -v)
    问题 这是控制台输出: sergio@sergio-VirtualBox:~$ rvm list rvm rubies ruby-1.9.3 [ i386 ] sergio@sergio-VirtualBox:~$ rvm use 1.9.3 Using /usr/share/ruby-rvm/gems/ruby-1.9.3 sergio@sergio-VirtualBox:~$ ruby -v The program 'ruby' can be found in the following packages: * ruby1.8 * ruby1.9.1 Try: sudo apt-get install <selected package> 发生什么了? 我需要重启机器吗? 还是应该立即发挥作用? 我正在使用Ubuntu 11.10,感谢您的帮助。 回答1 您的RVM版本已损坏。 Ubuntu对RVM产生了很多错误,目前唯一安全的修复方法是: sudo apt-get --purge remove ruby-rvm sudo rm -rf /usr/share/ruby-rvm /etc/rvmrc /etc/profile.d/rvm.sh 打开新的终端并验证环境是否与旧的RVM设置相清洁(应为无输出): env | grep rvm 如果有输出,请尝试打开新的终端
  • 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
  • Warning! PATH is not properly set up, usually this is caused by shell initialization files
    Whenever I go to a folder with a .rvmrc file, there is a warning: Warning! PATH is not properly set up, '/home/me/.rvm/gems/ruby-2.0.0-p247/bin' is not available, usually this is caused by shell initialization files - check them for 'PATH=...' entries, to fix run: 'rvm use ruby-2.0.0-p247'. I did rvm use ruby-2.0.0-p247, but the warning is still present. Note: There are no errors, Im able to run my application just fine, but the warning is very annoying. Any ideas?
  • 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
  • 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
  • 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
  • pod install -bash:pod:找不到命令(pod install -bash: pod: command not found)
    问题 我前一段时间安装了pod 。 但是,它已停止工作,因此我将再次进行此工作。 但是,我几乎立即在这里遇到了一个问题: pod install -bash: pod: command not found 有什么建议为什么会这样吗? 回答1 好的,找到问题了。 不久前,我升级了Ruby,炸毁了全部宝石。 解决方案: sudo gem install cocoapods 对于none-sudo使用: export GEM_HOME=$HOME/.gem export PATH=$GEM_HOME/bin:$PATH gem install cocoapods --user-install 回答2 在OS X 10.11上安装CocoaPods 这些说明已在所有beta版本和El Capitan的最终版本中进行了测试。 自定义GEM_HOME 当您收到上述错误时,这是​​解决方案 $ mkdir -p $HOME/Software/ruby $ export GEM_HOME=$HOME/Software/ruby $ gem install cocoapods [...] 1 gem installed $ export PATH=$PATH:$HOME/Software/ruby/bin $ pod --version 0.38.2 回答3 此步骤正常工作。 吊舱安装 [1
  • 您没有对/Library/Ruby/Gems/2.3.0目录的写许可权。 (Mac用户)(You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user))
    问题 下面是我需要做的。 要运行规格,您需要安装RSpec。 首先,在项目的根目录中运行gem install bundler 。 然后,运行bundle install 。 要运行单个spec文件,请运行如下命令: bundle exec rspec spec/00_hello_spec.rb 。 要一次运行所有规格,请运行bundle exec rspec 。 因此,我在终端中输入了gem install bundler ,并收到错误消息: 您没有对/Library/Ruby/Gems/2.3.0目录的写许可权。 这是在原子的项目文件中 source "https://rubygems.org" gem "rspec", "~> 3.2.0" 我的问题是: 似乎终端机给了我响应,因为我不应该更改ruby上的任何内容,而我需要将bundle install在atom内吗? 谁能告诉我如何使用原子或在原子中运行任何东西? 回答1 更新:从那以后,我就在Mac上安装Ruby gem的各种方式写了非常详细的说明。 我最初使用脚本的建议仍然存在,但是我的文章更加详细:https://www.moncefbelyamani.com/the-definitive-guide-to-installing-ruby-gems-on-a-mac/ 没错
  • RVM installed by Ruby not working?
    I installed RVM using the single instruction mentioned at the RVM website (using git). Then I installed Ruby version 1.9.2 and 1.8.7 using: rvm install 1.9.2 rvm install 1.8.7 However, I cannot find the Ruby binary. When I try to execute the command, I get the following error: [root@server1 support]# rvm use 1.9.2 Using /usr/local/rvm/gems/ruby-1.9.2-p136 [root@server1 support]# ruby -bash: ruby: command not found Here is the output of rvm info: [root@server1 support]# rvm info system: system: uname: "Linux server1.myserver.com 2.6.18-194.26.1.el5.028stab070.14 #1 SMP Thu Nov 18 16:34:01 MSK
  • 软件包安装失败,并显示SSL证书验证错误(bundle install fails with SSL certificate verification error)
    问题 当我在Centos 5.5上为Rails 3项目运行bundle install ,它失败并出现错误: Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://bb-m.rubygems.org/gems/multi_json-1.3.2.gem) An error occured while installing multi_json (1.3.2), and Bundler cannot continue. Make sure that `gem install multi_json -v '1.3.2'` succeeds before bundling. 当我尝试手动安装gem时(通过gem install multi_json -v '1.3.2' ),它可以工作。 其他几个宝石也会发生相同的问题。 我使用RVM(1.12.3),ruby 1.9.2,bundler 1.1.3。 如何解决? 回答1 更新 现在,我已经从这个答案中充分挖掘了..err,每个人都应该知道应该已经解决了这个问题。 回复:再次通过Ownatik捆绑安装失败