Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Installing Rails on Linux7:24 with Jay McGavren
Today, we're going to be setting up a Ruby on Rails development environment on Linux. We've chosen Ubuntu because it's a very common distribution, but you should be able to adapt these directions for other distros without too much trouble.
First, open a terminal. If you haven't done that before, you can click the button in the upper-left to search your computer, and type "terminal". Click the "Terminal" application in the list of results. Once that's done, you'll be ready to follow along for the rest of these directions.
Ruby Version Manager (rvm)
We need to install rvm, the Ruby Version Manager. rvm will download, compile, and install new Ruby versions for us.
But to install rvm, we first need the "curl" program. We'll install that via a package manager. In your terminal, run this command:
sudo apt-get install curl
You'll need to provide your system password. When the installation is complete, you'll be returned to your system prompt.
Now we're ready to install rvm. Copy and paste these two commands into your terminal:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -sSL https://get.rvm.io | bash -s stable
(Yes, that is a backslash before the "curl" command. It's there to avoid potential version conflicts.)
rvm is now installed, but it won't be available until you open a new terminal window. So go ahead and open a new window from the menu. Then, try running the "rvm" command all by itself. If it outputs usage information, you'll know it's working.
Now that rvm is installed, we can have it install a new Ruby version for us. From your terminal, run:
rvm install 2.3.1
rvm may need to install some packages that Ruby depends on. If it asks, type your system password and press Enter to continue.
When it returns to the system prompt, Ruby will be installed. But it's not available in your terminal yet. If you type
ruby -v to look at your ruby version, you'll probably either get a message saying Ruby is NOT installed, or you'll get an older version of Ruby. To tell rvm to use the Ruby version you just installed, and to use that version by default in the future, run:
rvm use 2.3.1 --default
Setting your terminal for login shell
When you try to run the "rvm use" command, you may get an error: "RVM is not a function... You need to change your terminal emulator preferences to allow login shell." If that happens, you'll need to go to a search engine to figure out how to enable login shell for your terminal.
If you don't know what terminal program you're using, you can look in the About menu. Ubuntu comes with "Gnome Terminal" by default, so that's what we used for this installation. So we'd type into a search engine: "gnome terminal login shell".
Among the results, we found a page that said "you have to enable 'Run Command as a login shell' in the gnome-terminal 'Profile Preferences', reachable from the Edit menu." So we followed the menus:
- "Profile Preferences"
- "Command" tab
- Check "Run command as a login shell"
- Click "Close"
- Open another new terminal window so it takes effect
After that, we ran
rvm use 2.3.1 --default again, and it worked.
Of course, these particular directions will only help you if you're using Gnome Terminal. If you're using a different program, try your own web search.
Now it's time to install Rails. Rails comes as a Ruby "gem". A gem is a library, a collection of reusable code, that can be automatically downloaded and installed on your system, using the "gem" tool. In your terminal, run:
gem install rails --version 5.0.0
The "gem" program will download and install that version of the Rails gem, along with all the other gems Rails depends on.
sudo apt-get install nodejs
You'll be prompted for your system password again, and then Node.js will be installed.
That's it! You should be ready to create your first Rails app!
Hi, I'm Jay, a teacher here at Treehouse.
Today we're going to be setting up a Ruby on Rails development environment on Linux.
We chose Ubuntu as the distribution to demonstrate here, but
you should be able to adapt these directions for other distros.
Be sure to check the teacher's notes for additional hints and
if you get stuck, try asking your question in the Treehouse community.
We use a package manager to install a set of tools that the rest of
the install process relies on.
We'll use RVM, the Ruby Version Manager, to install a new version of Ruby.
We'll use our newly installed Ruby tools to install the Rails library itself.
So will install Node.JS.
Let's get started.
First, open a terminal.
If you haven't done that before, you can click the button in the upper left
to search your computer, and type terminal.
Click the terminal application in the list of results.
In that terminal, use your package manager to install the curl package,
which we'll use the download the next item.
Type sudo, space, apt-get,
that's a dash character in the middle there,
space, install, space, curl.
Hit Enter to run the command and it may ask you for
your administrator password, so just type that and hit Enter.
It will ask you for confirmation before completing the operation.
Go ahead and type Y for yes.
And when it returns to your system prompt,
the package we requested will be installed.
Now we need to install RVM, the Ruby Version Manager.
RVM will download, compile and install new Ruby versions for us.
Go to a search engine and search for RVM.
It will probably be the first result.
Scroll down a bit and you'll see a pair of commands you need to run to install RVM.
Highlight the GPG command.
Don't include the dollar sign at the start,
because that's meant to represent your system prompt.
If we hover over the command,
the site will prompt us to triple click to select just the command.
Now, paste the command into your terminal.
Hit the Enter key to run it, and wait for the command to complete.
Now, for the second command.
Go back to your browser, highlight it in the same way as before,
making sure to leave the dollar sign prompt off the start but
to include the backslash at the start of the command.
Switch back to your terminal and paste the command.
Hit Enter to run it.
RVM is now installed, but
it won't be available until you open a new terminal window.
So go ahead and choose New Window from the terminal menu, New Terminal.
Try running the RVM command all by itself.
If it outputs usage information, you'll know it's working.
Now that RVM is installed, we can have it install a new Ruby version for us.
Run the rvm command,
followed by the install sub command with a version number of 2.3.1.
So our rvm, space, install, space, 2.3.1.
Hit Enter to run.
RVM may need to install some packages that Ruby depends on.
If it asks, type your system password and press Enter to continue.
When it returns to the system prompt, Ruby will be installed but
it's not available in your terminal yet.
If you type ruby- v to check the currently installed Ruby version,
you'll probably either get a message saying Ruby is not installed or
you'll get an older version of Ruby.
To tell RVM to use the Ruby version you just installed,
type rvm, space, use, space, 2.3.1.
Then, to tell RVM to use this version by default in the future,
add two dashes and the word default onto the end of the command.
Press Enter to run it.
When you try to run the RVM use command you may get an error,
RVM is not a function, and a prompt saying you need to change your terminal emulator
preferences to allow login shell.
If that happens, you'll need to go to a search engine to
figure out how to enable login shell for your terminal.
If you don't know what terminal program you're using,
you can look in the About menu.
Looks like we're using Gnome Terminal.
So we'll type into a search engine Gnome Terminal login shell.
We'll look at the first result.
Looks like this answer references another answer.
And here it says to do that, you have to enable run command as a login shell in
the Gnome terminal profile preferences, reachable from the Edit menu.
So as the post says, we'll go to the terminal Edit menu and
choose Profile Preferences.
We don't see the option we need here, so we'll check the next tab.
Here it is, click Run command as a login shell, and then click Close.
Again, this won't take effect until you open a new terminal window, so
choose New Terminal from the menu.
Now type your command again.
Rvm, use, 2.3.1 -- default.
This time it should work.
Typing Ruby dash v should give us a version of 2.3.1.
Now it's time to install Rails.
Rails comes as a Ruby gem.
A gem is a library, a collection of reusable code that can be automatically
downloaded and installed on your system using the gem tool.
In your command prompt, type gem install followed by the name of the gem we want,
which is Rails, but don't hit Enter just yet.
If you want to simply install the latest version of Rails, whatever it was,
you could just hit Enter here.
But we wanna specify a particular version of Rails to install to make sure that all
the code we show you during the upcoming courses will work the same way.
So we're going to add -- version 5.0.0 onto the end.
That will ensure that we install the specific version 5.0.0 of the Rails gem.
Once you press Enter, the gem program will download and install version
5.0.0 of the Rails gem along with all the other gems Rails depends on.
It may take a while so give it a few minutes to complete.
When it returns to your system prompt, Rails will be installed.
There's one last thing we need to take care of.
Let's install Node.JS so that those libraries work properly.
In your terminal, use your package manager to install the node.JS package.
Type sudu Apt-get.
That's a dash in the middle there.
Install nodejs, all one word.
You'll be prompted for your system password again.
And then Node.JS will be installed.
Be sure to confirm yes if you're asked if you want to continue.
And when it returns to your system prompt, Node.JS will be installed.
You should be ready to create your first Rails app.
You need to sign up for Treehouse in order to download course files.Sign up