Very awkward upgrade, do I understand enough about rails and how to speed up gem updates?

I Installed rails_4.2.10 from the Ubuntu package. I began working through the Rails Guide for v6.0.3.2 and I got up to where form builder was supposed to draw boxes on the screen. At that point, what I wanted was to dump the output of the View. I couldn’t figure that out so I tried using the view source feature of the browser. All that was present there was the text of the “something went wrong” error message. Eventually I decided I needed to upgrade “Rails” and I went hunting for instructions on how to upgrade the version level of Rails. I was disappointed that there are no ‘tar files’ for just copying new files. Then I thought, rails is a Gem. I should be able to upgrade rails by using the Gem program. After upgrading the rails gem to 6.?.? That worked. now when I run “rails server” I am getting a series of errors about about gems, like Could not find gem 'webpacker (~> 4.0). What do I need to understand about Gems and gem versions? Thanks for a reply. A pointer to the Rails documentation would be appreciated too.

A Rails project involves a collection of gems which are declared in your Gemfile. You can’t just gem update a single one since gems depend on other gems of a specific version. In your case, bundle update rails will upgrade Rails and all dependent gems in your project.

However, upgrading Rails 4 to Rails 6 requires a lot of additional changes to your project files. You’d probably be better off starting a new project from scratch with Rails 6.

3 Likes

Agree. Just start over from scratch. Many other changes have been introduced and you’re using a Rails 6 tutorial anyway. You’ll do a better job the second time anyway. At some point you were going to have to start over.

1 Like

Per the upgrade guide, you should be upgrading Rails once for every minor version (the second number).

Upgrading from Rails 4.2 to 6.0 is a 4-step process.

Upgrade from Rails 4.2 to 5.0 Upgrade from Rails 5.0 to 5.1 Upgrade from Rails 5.1 to 5.2 Upgrade from Rails 5.2 to 6.0

If you just jumped from 4.2 to 6.0, a lot is going to be broken, probably without much explanation, since it wasn’t expected that you’d attempt 4 upgrades in one step.

Maybe I’m misunderstanding what you did.

2 Likes

Nate, thank you for the suggestion. On the advice of a previous responder I made a new directory structure,

In that new directory I played around until rails --version came back “Rails 6.0.3.2”.

Next, on the further advice, I ran bundle update. I am beginning to catch on to the wild and wooly style of having many gems and having to be careful to get the conventional things in place.

So I am cheerfully racing ahead, about half way through the Tutorial. It is neat, I am beginning to see how the typical problems of building a website have a pathway already laid out.

Thanks again. In a few days I hope to be getting to the problems of testing and deployment. Lets see what I can figure out from the tutorials.

Cordially yours, Lee

confusingly, bundler can have more than one version of rails installed at once. if you had many versions, when you ran rails new, it probably used the default one, which was 4.2 for you.

to see which versions of rails you have installed in bundler, use

gem list |grep rails

(here you are grepping, or searching against, the output for the string “rails”; without grep you would see all of your gems)

(you’ll see some other gems with the name “rails” in them too, fortunately all the rails gems are numbered concurrently)

TO install a different version of Rails in your bundler (remember, this just installs the gem code in your bundler’s system ready for use)

gem install rails -v 5.2.4.3

Finally, if you want to force rails new to use a specific version

rails _6.0.3.2_ new

@Lee_McKusick I would just like to clarify as the message is dated August 18 this year and you are referring to Rails 4.2. If I understand correctly, you have Ubuntu 18.04 LTS (bionic) and you chose to install the Rails framework using the standard procedure: apt install ruby-rails (package: https://packages.ubuntu.com/bionic/ruby-rails, of course you can use apt-get install or aptitude install, the effect will be the same). If that’s true, then, like @ferngus and @MtnBiker , I recommend starting from scratch. Ubuntu packages are not recommended sources for rapidly changing web frameworks like Ruby on Rails, Django, Sinatra, or Flask. In fact, this applies to a much larger group of packages available in Ubuntu - including Ruby or Python installations too. It is best to leave system packages for use only for system utilities, and when working on your own project, it is better to install the language and libraries yourself. In the case of Ruby, first I recommend installing RVM (rvm.io), only after installing and using Ruby download the latest version of Rails (gem install rails)). The same approach can be applied to Javascript and nodejs (install nvm and download the appropriate version of nodejs, regardless of what Ubuntu offers) and Python (pyenv + pipenv).

1 Like

Thank you Janusz M for the Rails installation advice. I found my way to a Rails 6 installation by removing the Ubuntu packages, running the gem and bundle programs and installing node.js and Yarn. I have worked through the Ruby introduction, and I worked through the getting_started.html. The zero problem for me is how do I implement state of the art hack resistance on my amateurish Rails prototype? On the public facing side of things, I have a computer in the garage with Ubuntu 20 and a 500 Gig solid state disk. I would like to migrate my rails setup with a couple tar files. Then, I’ll use a web redirect statement running on the noip dot com service. Hmm, what could possibly go wrong with that scheme?