简体   繁体   中英

How do I upgrade the Ruby version of my project?

I recently started learning Rails using Ruby 1.9.3p385, and I'm trying to develop a small project with it.

I'm using Linux so I installed Ruby using RVM.

I developed a few pages, following some tutorials. I would like to upgrade my project to use Ruby 2.0.0. What do I have to do?

I installed Ruby 2.0.0 with RVM:

rvm install 2.0.0

Everything seems OK, so I tried to use it:

rvm use 2.0.0-p247

But when I try to run my Rails server using rails server , I get the following message:

bash: rails : command not found

I've read the RVM documentation about upgrading Ruby but I don't really understand what it does; I'm afraid of breaking everything.

Does it will upgrade my project in a way it will use Ruby 2.0.0 or what should I do?

Next, I will want to upgrade also to Rails v4.

Your gemset which comes with new Ruby version is empty. Try this:

gem install bundler # this will install bundler
bundle # this will use bundler to install required gems
rails server

Did you run rvm use 2.0.0-p247 or did you use rvm use 2.0.0-p247 --default ? The later will set Ruby v.2.0 as the default for your system. Failure to do that will revert your Ruby to whatever RVM's default is the next time you log into your system or open a new terminal window.

When RVM installs a new version of Ruby, it installs only the default gems. It CAN upgrade a Ruby to another version, and optionally install the existing gems as it does so, but that's not what you asked it to do: rvm install 2.0.0 only installs Ruby. At that point you have to install the other gems you need, which would include Rails.

My general practice when installing various versions of Ruby and the gems I like is to use two command-line pipes to dump my existing gems, then (re)install them. First I switch to an existing Ruby whose gems I want to duplicate, then run:

gem list | cut -f1 -d' ' > ~/gem_list

Then I switch to the newly installed one, and run this:

xargs gem install < ~/gem_list

This does a completely clean install of the gems, outside of RVM's commands.

Why? Habit. Paranoia based on some "experiences" I had in the past with RVM.

Once that's all done and I have brand-spanking-new Ruby and gems, I'll proceed with running bundler or other housekeeping chores.

when you install a new ruby version, you have to reinstall all the gems for that version. start of by installing bundler first. Then run bundle in your rails root directory. When you encounter no errors, you're good to start the rails server. Good luck!

在应用程序根目录上运行bundle install ,您需要为新版本的Ruby重新安装所有依赖项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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