We use Ubuntu 12.04 TLS, Ruby 1.9.3, Rails 3.2.12, and RVM on our production server.
We want to upgrade Ruby from 1.9.3 to 2.2 (or whatever the latest one is), without updating Rails.
I have three questions:
Are there any caveats in doing that, any inconsistensies, deprecated methods? Is there any chance that site will stop working?
Considering that we are using RVM, would it be possible to get back to the version we are using right now (if anything goes wrong)?
Would it be necessary to re-install all the gems that we are using right now?
Thanks in advance!
Always presume the whole machine is going to be trashed beyond repair by this process. Prepare for the worst, hope for the best. If you don't have a test machine, you can build one with a tool like Vagrant. Once you have a procedure that works, repeat it on your production system.
Ruby 2.1.1 is the current version. You'll also want to look at upgrading Rails itself to avoid a bunch of nasty vulnerabilities. 3.2.17 is the version to target here.
RVM does make it easier to upgrade things, but you'll also need to upgrade your launcher (e.g. Passenger) to use the newer Ruby version. Yes, it is possible to back out, but this is not always convenient.
One trick that might help rescue from disaster is checking your /etc directory into a local Git repository. This allows you to rollback any configuration changes you make, as well as see what changes you've actually made through the course of your upgrades.
Any change to the base Ruby version does require re-installing all gems. If you're using Bundler or an automated deployment tool this should be fairly automatic.
Related
I have a few Rails apps, each running on their own server. They run under Passenger-apache, and currently under ruby 1.9.3. Currently, they run under a ruby installed and managed with rbenv.
I'd like to upgrade them all to ruby 2.2.x. As long as I'm doing this, I'd like to upgrade them from passenger 4.x to 5.x as well.
Let's assume I've tested them all on my development box and am confident they run fine under ruby 2.2.
As I think through this, I get very confused about the best way to do this -- especially with minimal production downtime.
I guess I'd start out by installing ruby 2.2 under rbenv, which theoretically shouldn't disturb the running apps. Passenger is installed under a particular ruby, but then has the option of running apps under different rubies. Should I install the latest passenger first, under the new ruby 2.2, but configured to run the existing apps under the old ruby? And then upgrading the apps to the new ruby... I guess involves running bundle install again, to get all dependencies installed under the new ruby?
Or something else entirely? Is there a way to do this that is relatively safe, and will have limited or zero downtime for my apps?
Has anyone done this before? I'm fairly familiar with all the pieces already, and can brainstorm possible approaches myself, but when I start, there are too many places where I'm not sure what the best approach is. What I could really use is advice from someone who has already done this, or is otherwise pretty sure that what they recommend will work as they say -- not just guesses about things you haven't done that might work. Thanks!
Make sure that your applications work under the new ruby version. I have had some legacy Rails 3.2.x applications that works up to ruby 2.1.5, but breaks in ruby 2.2.x. You should be fine with updating your ruby and passenger versions.
Since each application runs on their own server, you don't have to really worry about running multiple versions of passenger. You should be able to install the new version ruby on each server, install the gems, update apache to the newer passenger and restart apache to have everything take effect. Worst case, you can clone your servers to a virtual environment and test everything prior to doing it on production. This would help you minimize downtime as you would have any workarounds and/or research of bugs done prior to touching the production environment.
I've read through a few Q&A's here on this subject, but am still confused. I'm new to linux and new to programming, so please keep that in mind.
I understand that Ruby Gems is similar to apt-get. It's a package manager -- correct?
So if I want to install or remove gems, I can do it via a command like: sudo gems install {gem name}
So what then is RVM? Why would I want to use it? Doesn't Ruby Gems do what RVM does? Why then does Ruby Gems get installed with RVM?
Also, when specifying gems in a project's Gemfile, then using bundler to update, etc.. is this downloading the gems only to that project, or will they now be available across all projects?
Also, what is $PATH about? I don't know much about it, so when I read about it, I'm confused about what is the right $PATH, what if anything I should do to manage references in $PATH, etc. Can someone explain or point to any resources for beginners?
And finally, I'm using various tutorials, and they differ on versions for everything from Ruby to Rails to Gems. a) Should I be modifying my environment to match the version that they use? b) Once I'm done with a tutorial, should I leave all the versions alone, or should I try to upgrade everything up to the latest and greatest?
It's confusing because if I leave everything at the version levels in the tutorials, then I feel like I'm stuck in the past. While if I upgrade to the latest and greatest, I feel like things have all switched around on me and I'm not sure how to use all the tips and tricks I learned.
Thank you in advance for taking the time to help. Cheers.
This question is very broad so I chose to try to balance the explicitness with conciseness. If anyone finds anything wrong with the answer please tell and I'll straight up own up to it :)
RVM is a Ruby Version Manager. Hypothetically, some projects might require you to run ruby 1.9, another legacy project might require 1.8. RVM allows you to have both installations installed side-by-side, as opposed to having one authoritative system-level version of ruby. This facilitates installing later versions of ruby without fear of breaking anything, or of meddling with other user accounts' ruby version requirements (since usually one installs RVM at the user level, in your home directory). This even lets you try out the bleeding edge version of ruby without having anything to worry about, since you can always switch back easily.
When you install a gem, it generally becomes available to you everywhere that ruby installation is available to you, so in any project. When you specify gems in your Gemfile you're basically saying that independently of whatever gems you may have installed and their versions, that project requires gem x of version 2.2, y of version 3.1, and z of version 1.1. If you didn't already have those gems it installs them, if you did but not those versions, it installs them.
Path is an environment variable that allows operating systems to know where to look for programs when you invoke them. If you type someapp in the terminal, how can the operating system possibly know where someapp is? Well it searches for it in any of those directories supplied in $PATH. You can see what's in your path by doing echo $PATH in the shell.
As for varying versions of ruby, this brings me back to the reason for RVM. You can if you want install the version of ruby they use, and then in your Gemfile specifically state the version of the gems the tutorials use and you should be fine. You can have different versions of gems installed, and you can have different versions of ruby installed thanks to RVM.
Personally I would recommend working towards the latest version of everything so that it remains relevant. For example, it would be counterproductive to work on a tutorial that uses Rails 2 since it changed a lot when it went to 3, and somewhat from 3 to 3.1 and above etc. If possible use the latest versions, or at least be aware of the nuances (the base material tends to stay more or less the same), lest you work on a tutorial that is older only to get to work on your own project with the latest version of everything and not have it work.
Simple solution to your dilemma: ditch the tutorials that are too old. There are tons of resources out there that you're bound to find up-to-date material. Worst case, dated material typically has community support in form of comments which state the changes between the dated version of something and its corresponding recent version. E.g. "keep in mind that haha.what changed to lol.wut in version 3.1"
I can understand that this is confusing, RubyGems are as you write a package manager. RVM is a tool that makes it possible to have several versions of ruby installed on your system and easy swift between them.
If you using various tutorials, and they differ on versions for everything from Ruby to Rails to Gems you can (if you want to) create a RVM Gemset for the version you use. You will then create a sandbox for the Gems Bundler use in your project.
Bundler are as you write a tool for manage the Gems your application depends on. In the old days before Bundler it could be a hassle to figure out which gems your application depended on. Now Bundler do this for you.
Both Bundler and RVM are tools that is not absolutly necessary to use but they will help you. I personally do not use RVM anymore. It is to much of a monster in my taste so I use rbenv instead.
Regarding what versions of Rails to use I do agree that you should try to use 3.1 versions if possible but if you find some example application using Rails 3.0 you do not need to upgrade it. Also you do not need to run the absolute latest version of Rails. Rails 3.1 have a lot of bug fixes that the latest Rails 3.1.3 might not have.
So, I upgraded Ruby to 1.8.7 to make a particular gem work. Hooray, it works now! But...now rails doesn't. I tried reinstalling rails through gem, but that hasn't helped, either. Rake is no longer recognized by my windows box as a valid command, and I can't even start the server without a whole string of errors.
My only thought is that maybe I shouldn't have copied my gems file over (a tutorial mentioned it as the only way to save my gems on windows with an upgrade). I'm gonna try reinstalling 1.8.7 without changing anything, and reinstalling everything as needed.
Edit: Okay, just plain 1.8.7 does work, but it's frustrating to have to reinstall all my gems by hand... Is there any better solution, in Windows?
You may have to uninstall the old version first or use something like RVM to manage your multiple versions. I've always run into problems trying to upgrade directly on a windows machine (rake and rails not working basically).
Edit: Looks like even with RVM you have to install gems individually for each version (a good thing), but you can also export and import gem sets. That might be your best bet, short of scripting a solution yourself.
That is normal: each ruby environment has their own set of gems. That might not seem intuitive, but i guess it has something to do with the possible differences in ruby versions and the fact that gems are "installed" and compiled if needed.
I have a script that installs all my needed gems on windows. On windows rvm does not work, but there is an alternative called pik. I have written a blogpost about this process, which also contains a small bat-file i use that will install the most commonly used gems automatically.
OSX 10.5 comes with Ruby 1.8.6 I believe, but I see a lot of tutorials that recommend installing the latest version of Ruby from source. I've done this in the past and it's caused minor issues down the road if I install something which expects Ruby to be in the default location and it's not (Phusion Passenger pref pane, for instance).
What I'm wondering is if the default version of Ruby is good enough to use for development purposes, so there's no conflicts or multiple versions of Ruby floating about? Obviously the default Rubygems and Rails versions would need to be upgraded, but I'm specifically wondering about the default version of Ruby that comes with 10.5.
Rails 3 will require Ruby 1.8.7 and we're already recommending 1.8.7 for Rails 2.3.4. I'd strongly recommend upgrading.
1.8.6 will be fine for a local dev box. Personally I always install what's on the production box -- usually Ruby Enterprise -- but yea, if you don't want to deal with the hassles involved with replacing ruby entirely, there's no big disaster waiting for you with the stock stuff.
If you do want to keep current (probably a good idea for a serious application) and make sure you're running the same ruby as your production environment then you could try this tutorial (I've used a previous iteration) on handling those hassles.
The Rails team themselves recommend Ruby 1.8.7 for doing Rails development with any of the most recent releases.
I'd also highly recommend that you use the same version of Ruby for development as what will be in your 'production' environment. Avoids surprises.
The Ruby on Rails download page recommends 1.8.7 but says 1.8.6 still works and I'm finding no problems.
I personally do not like the Ruby implementation on the Mac, as I had a a lot of problems with MySql, Postgres, and other gems, always being obscure compilation problems which required me to install XCode and then compile all sorts of obscure libraries. In the end I solved my problems by installing Ubuntu 8.10 on VirtualBox under the Mac, and now everything works great!!!!
Also, when I switched to Snow Leapard I had a lot of the Ruby gems break as well. Also, I would recommend using Ruby 1.9, definitely much faster than 1.8.6 IMHO, again, running best on Ubuntu, NOT Mac.
I guess I would also like to add that many Unix die hards will disagree with me on this post, as things on the Mac CAN be made to work, but I guess I'm just lazy, and would rather have things "work out of the box".
I run REE (Ruby Enterprise Edition) simply because it runs my specs faster than the regular version (about 20%, sometimes more).
It's also nice that it comes with passenger and some of other things you usually want.
I'm used to the One-Click install local environments of MAMP. Is there a Ruby equivalent... a download that you run and instantly get the most current versions of Ruby, Rails, SQLite running locally?
I'm using a Mac, running Leopard, and am aware that all of the aforementioned technologies ship with Leopard (except maybe SQLite). The books that I have reference newer versions and the last thing I need is to try to retrofit a tutorial to work with my version.
And one more less important question: What are "Gems" and is that something that I need to make sure is fully updated too?
Installation is pretty confusing when you first start with Rails! Even though a lot of what you need is already installed if you are using Mac, personally I found it really hard to find come concise information on how to best go about setting things up.
Since I didn't want anyone else to go through the headaches that I had when configuring their Mac development environment, I've written a 7 step guide to installing Ruby on Rails, MySQL, Apache with PHP, and phpMyAdmin on OSX Leopard. In short, everything you should need to get developing locally on your Mac!
Here's the link:
http://waavoo.com/2009/7-step-guide-installing-ruby-on-rails-mysql-apache-php-phpmyadmin-intel-mac-os-x-leopard/
Hope that helps!
Take a look at FiveRuns Install. It's a free Ruby on Rails stack that you can download.
RubyGems is the Ruby standard for publishing and managing third party libraries. Check out the User Guide.
Have fun!
I have no idea what mac os are you in but Leopard (10.5.x) already have ruby installed, all you need is to updated the gems using
gem update rails
in your command line.
if you're on Tiger (10.4.x) the installation is broken, and please follow this link.
You should also have a look at Phusion Passenger - this, along with the prefpane, allows you to have apache VirtualHosts set up the easy way.
Current versions of Rails are designed to work (for development) without needing an AMP -style stack, by using SQLite and a small Ruby Web server, so if you will only be doing Rails development you don't need to set up a stack - you can just type "rails" and it will work.
BUT the versions of RubyGems and Rails shipped with Leopard are now outdated, though, so you'll need to upgrade these before you go too far. There's an article that I wrote on setting up a Mac for development here, but the minimum commands go like this:
sudo gem install rubygems-update
sudo update_rubygems
sudo update_rubygems (yep, twice)
sudo gem update --system
These get RubyGems up to the current release, so that you can upgrade Rails safely. To do that, type:
gem update rails
The last command doesn't have sudo, because if you omit it, current versions of RubyGems will install a clean copy of the gems into your home directory, leaving the system versions untouched.
Finally, amend the .profile file in your home directory, so that the line with PATH in it says:
export PATH=$HOME/.gem/ruby/1.8/bin:$PATH
Close up any terminal windows for this to take effect. The utilities provided by the gem packages in your home directory will now have precedence over the system versions.
This means that you can type "rails" and the latest version will run, but you haven't messed with any of the software provided by Apple (apart from the system copy of RubyGems).
To upgrade your private copy of Rails whenever a new version comes along in future it's just this again:
gem update rails
just refer this....
http://wiki.rubyonrails.org/getting-started/installation/windows#installing_ruby_on_rails_on_windows
BitNami RubyStack is exactly what you are looking for http://bitnami.org/stack/rubystack