简体   繁体   English

能够在Ruby on Rails版本之间切换,一个版本来自rbenv,另一个版本来自rvm

[英]Ability to switch between Ruby on Rails versions, one from rbenv, other from rvm

I first used rbenv to install ruby ver 2.2 and Rails ver 4.2 on Linux CentOS 7, then used rvm to install ruby ver 2.4 and rails ver 5.2. 我首先使用rbenv在Linux CentOS 7上安装ruby ver 2.2和Rails ver 4.2,然后使用rvm安装ruby ver 2.4和Rails ver 5.2。 Is there a way to switch between these easily or do they both have to be installed using the same method for this to work? 有没有一种方法可以轻松地在它们之间切换,还是必须使用相同的方法将它们都安装才能起作用?

Better you can use rvm. 更好的是您可以使用rvm。 Rvm is the better tool to switch between many versions with the command Rvm是使用命令在多个版本之间切换的更好工具

rvm use ruby-2.5.1 or rvm use 2.5.1 rvm use ruby-2.5.1rvm use 2.5.1

For list out all rvm just use 要列出所有rvm,请使用

rvm list rvm列表

within rvm, you can manage the versions nicely no need of rbenv here. 在rvm中,无需rbenv即可很好地管理版本。

I prefer RVM, it's easy to switch between version, also you can use multiple rails version for that ruby easily 我更喜欢RVM,很容易在版本之间切换,也可以轻松地将多个Rails版本用于该Ruby

install rvm, install ruby and create a gemset with rvm use 2.4@rails_5_2 --create will create a gemset with name rails_5_2 安装rvm,安装ruby并rvm use 2.4@rails_5_2 --create创建一个gemset rvm use 2.4@rails_5_2 --create将创建一个名为rails_5_2的gemset

for switching between versions. 用于版本之间的切换。 I use .ruby-version and .ruby-gemset files in my project so i don't need to specify version all the time 我在项目中使用.ruby-version.ruby-gemset文件,因此我不必一直指定版本

in the .ruby-version file write the ruby version 在.ruby-version文件中编写ruby版本

2.4

and inside ruby-gemset write gemset name 在ruby-gemset里面写gemset名称

rails_5_2

so whenever you will run the project it takes ruby and rails version from there 因此,每当您运行项目时,都会从那里获取ruby和rails版本

you can create this two file manually or you can run this command in terminal from your application directory which will create this two files 您可以手动创建这两个文件,也可以在应用程序目录的终端中运行此命令,这将创建这两个文件

rvm --ruby-version use 2.4@rails_5_2

I fixed this by removing RVM and installing the newer versions with rbenv instead. 我通过删除RVM并使用rbenv安装较新的版本来解决此问题。 Having both versions installed with the same method allowed it to be easy to switch when needed. 使用相同的方法安装两个版本可以轻松地在需要时进行切换。 The shims automatically use the correct Rails versions for each project respectively. 垫片会自动为每个项目分别使用正确的Rails版本。 As far as I can tell, the Rails versions are locked in with whichever one you started the project with. 据我所知,无论您使用哪个项目启动Rails版本,它们都被锁定。 You can switch the Ruby version for each project by using: 您可以使用以下命令为每个项目切换Ruby版本:

# rbenv local 2.4.1

I chose rbenv over rvm because I read several articles of people praising rbenv's lightweight approach and ease of use over rvm. 我选择rbenv而不是rvm,因为我读过几篇文章,称赞rbenv的轻量级方法和易用性而不是rvm。

NOTE: the "#" character is the beginning of the command line in Linux CentOS 7, NOT a character that you type in. 注意:“#”字符是Linux CentOS 7中命令行的开头,而不是您键入的字符。

EDIT: Thank you guys for the recommendations, though. 编辑:谢谢你们的建议。 It got me to look more into using rbenv vs. rvm. 我不得不更多地考虑使用rbenv vs. rvm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM