Introduction
Setting up a Ruby development environment on Windows 10 using the Windows Subsystem for Linux (WSL) can greatly improve your programming experience. With tools like Bash and the Ruby Version Manager (RVM), you can seamlessly integrate Linux-like capabilities into your Windows machine. This guide will walk you through the installation process and ensure everything is running smoothly so you can start coding efficiently. Whether you’re new to Ruby or just setting up a new environment, this tutorial covers everything you need to get started, from installing essential tools to creating your first Ruby program.
What is Windows Subsystem for Linux (WSL)?
WSL is a feature on Windows that allows users to run Linux tools and programs, including Ruby, directly on a Windows computer. It enables the use of Bash and Linux command line tools for development, solving compatibility issues that occur when running Ruby on Windows. By installing WSL, users can work with Ruby in an environment similar to Linux, making it easier to set up and run Ruby programs.
Step 1 — Installing Bash on Windows
Alright, let’s jump into setting up the command line so we can get Ruby running on your system. Now, I know the command line might sound a bit intimidating if you’re not used to it, but don’t worry! It’s just a simple text-based way of interacting with your computer. No need for clicking around with a mouse or dragging icons—just pure typing. This is known as a “shell,” and it’s a powerful tool for developers because it helps automate tasks and makes things much more efficient. Once you get the hang of it, you’ll wonder how you ever worked without it.
So, Windows 10 gives you two command-line options right out of the box: the classic Command Prompt and PowerShell. But here’s the catch—since we’re working with Ruby, we’re going to install Bash, which is the shell commonly used in Linux and macOS systems. If you’ve used a Linux or macOS computer, you’re probably already familiar with it. But don’t worry if this is all new to you. I’m here to walk you through it step by step, and soon you’ll be a Bash expert.
Now, before we get started, if you’re feeling a little nervous about using the command line, maybe check out a basic guide on using the Linux terminal. It’ll help you get comfy with the basics, but trust me, I promise this will be easy and straightforward.
Let’s start by enabling Developer Mode on your Windows machine. First, open the Settings app, go to “Update & Security,” and then look for the “For Developers” section on the sidebar. Once you’re there, check the “Developer mode” option and hit “Yes” when the prompt pops up. This will prepare your system for the next steps.
Next, open up the Control Panel and click on “Programs.” In the Programs window, select “Turn Windows features on or off.” In the list that shows up, check the box for “Windows Subsystem for Linux (Beta).” This is the key to running Bash on your Windows machine. Click “OK,” and Windows will start installing everything it needs. This might take a few minutes, so just sit tight.
Once that’s done, it’s time to restart your computer. Don’t skip this step! It’s really important because if you don’t restart, things won’t work properly.
After your computer restarts, open up Command Prompt again and type
$ bash
Once Ubuntu has been installed, the system will ask you to create a UNIX user account. This doesn’t have to be the same as your Windows username, so pick whatever you like. Let’s say you type “Sammy” as your new UNIX username. You’ll also be prompted to create a password for your UNIX account. Just a heads-up: when you type your password, you won’t see any characters appear on the screen—that’s normal! It’s just a security feature to protect your password. Once you’ve entered it, press “Enter,” and you’re good to go.
Now, Bash will start running, and you’ll see a prompt that looks something like this:
sammy@yourmachine:/mnt/c/Users/Sammy$
At this point, I want to highlight something important. You’ve probably noticed that the Windows Subsystem for Linux (WSL) has its own file system, which is stored in a special folder. Just so you know, Microsoft doesn’t support accessing this file system from Windows apps like your typical text editors or file managers. But don’t worry! You can still access all your files from within Bash. For example, if you look in the /mnt/c directory, you’ll find all the contents of your C: drive. This is a great way to work with your files directly from Bash while still being able to open and edit them with your usual Windows tools.
Here’s a tip: when you’re working with files in WSL, it’s best to stay within the /mnt/c directory. Trying to access files outside of it from Windows apps could cause data corruption, and that’s definitely something we want to avoid.
Now that Bash is up and running, you’re ready for the next step—installing RVM (Ruby Version Manager). RVM will make managing Ruby and all its dependencies a breeze, helping you get Ruby set up quickly and without any headaches. Stick around for the next step!
Getting Started with Bash on Windows
Step 2 — Installing RVM and Ruby
Imagine you’ve just set up your Bash shell on Windows 10. You’re super excited to get started with Ruby, but there’s still a little more to do before you can start writing code. That’s where RVM, or Ruby Version Manager, comes in. Think of RVM as your personal assistant, making sure Ruby is set up smoothly on your system. It’s an essential tool that works perfectly whether you’re on Ubuntu, macOS, or, in our case, Windows. RVM will simplify things by managing Ruby versions and installing any needed dependencies.
Alright, let’s get started with RVM! The first thing we need to do is make sure the installation process is safe and secure. To do that, we’ll grab the RVM project’s key from a public key server. This key ensures that the version of RVM you’re about to download is legit. To do this, type the following:
$ gpg –keyserver hkp://keys.gnupg.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Next, we need to install the gnupg2 package. This package helps the RVM installation script verify that everything is good to go. Don’t worry; this step is pretty simple. Just type this:
$ sudo apt-get install gnupg2
When you press Enter, you’ll be asked for your password. Don’t be surprised when you don’t see anything appear on the screen while typing—it’s just a security measure. Type in your password and hit Enter to keep moving.
Now, for the fun part! We’ll use curl to download the RVM installation script. The backslash before curl is there to make sure we’re using the right version of the command, keeping things clean. Type this to start downloading the script:
\curl -sSL https://get.rvm.io -o rvm.sh
Let’s break this down a bit. The -s or --silent flag stops curl from showing the download progress. The -S or --show-error flag ensures that any errors show up right away. The -L or --location flag tells curl to follow any redirects if the page you’re trying to download from moves somewhere else. Once the script is downloaded, you can review its contents by typing:
$ less rvm.sh
You can scroll through the file using the arrow keys. When you’re ready, press q to quit and go back to the terminal. Now, let’s install the latest stable version of RVM by running this command:
$ cat rvm.sh | bash -s stable
Here’s what happens next: the RVM script will create a folder called .rvm in your home directory. This is where Ruby and all its related tools will live. It will also update your .bashrc file to include the .rvm/bin folder in your system’s PATH, making the rvm command available anytime you open a terminal. However, since we just set it up, you won’t be able to use rvm in the current session until we run the following command:
$ source ~/.rvm/scripts/rvm
Now that RVM is installed, it’s time to get Ruby up and running. To install the latest version of Ruby and set it as the default, type:
$ rvm install ruby –default
Ruby will begin downloading, along with all the components it needs. This might take a bit, but hang in there—it’ll be worth the wait. Once it’s finished, Ruby will become the default version on your system, making sure there are no conflicts with any previous Ruby installations you may have.
During installation, you might see some messages like this:
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/16.04/x86_64/ruby-2.4.0.tar.bz2
If RVM finds that anything is missing, it will automatically download and install those necessary dependencies. For example, it could install packages like gawk, libssl-dev, and libyaml-dev. As it installs these, you’ll see something like this:
Installing required packages: gawk, libssl-dev, zlib1g-dev, libyaml-dev, libsqlite3-dev, sqlite3, autoconf, libgmp-dev, libgdbm-dev, libncurses5-dev, automake, libtool, bison, libffi-dev, libgmp-dev, libreadline6-dev
Once all the dependencies are installed, Ruby and its components will continue downloading. You’ll see something like this:
ruby-2.4.0 – #configure
ruby-2.4.0 – #download
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16.4M 100 16.4M 0 0 4828k 0 0:00:03 0:00:03 –:–:– 4829k
And just like that, Ruby will be installed! Along with Ruby, RVM will also install some handy tools like irb (the interactive Ruby console), rake (for running automation scripts), and gem (to help you manage Ruby libraries). To check that Ruby is properly installed, just type:
$ ruby -v
This will show you the version of Ruby you’ve installed, like this:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
At this point, Ruby is all set up and ready to use. However, there’s one more step to make sure RVM always uses the Ruby version you just installed when you open a new Bash session. RVM makes changes to your .bash_profile file, which only works with login shells. By default, the Bash shortcut on Windows doesn’t start a login shell, so you’ll need to start Bash as a login shell manually. To do this, open a new Command Prompt and type:
C:\> bash -l
If you forget to do that, no worries! You can just run this command every time you start Bash:
$ source ~/.rvm/scripts/rvm
And there you have it! Ruby is installed, RVM is set up, and you’re ready to start coding. Now, go ahead and write your first Ruby program and dive into the world of Ruby development!
Step 3 — Creating a Simple Program
You’ve done the hard work of setting up Ruby on your Windows 10 machine with Bash, and now it’s time for the fun part: writing your very first Ruby program. It’s one of those moments every programmer goes through, you know? We’re going to start with the classic “Hello, World!” program. It’s simple but powerful because it helps you check if everything is working just right. Plus, it’s a great way to see how Ruby scripts come to life.
So, let’s jump right in. First, you’ll need to open up your terminal. You know, that black screen with all the text—it might look a bit intimidating at first, but trust me, it’s about to become your new best friend. Once you’ve got the terminal open, you’re going to create a new Ruby file. Let’s call it hello.rb. To do that, you’ll use the nano text editor. Go ahead and type:
$ nano hello.rb
Now you’re in the editor, and this is where the magic happens. Go ahead and type the following Ruby code into your file:
puts “Hello, World!”
That’s it—just one simple line of code. The puts method is one of Ruby’s most basic commands. It’s used to print text on the screen, and in this case, it’ll print “Hello, World!” right in your terminal. You might be thinking, “Is that it?” But here’s the thing—this one line of code is all you need to prove that your environment is ready to run Ruby scripts. Pretty cool, right?
Once you’ve typed that out, it’s time to exit the editor. You can do that by pressing CTRL+X. When you do, you’ll be asked if you want to save the changes you’ve made. Don’t stress, just press Y for yes, then hit Enter to confirm the filename. This saves your file as hello.rb.
Now, the moment of truth has arrived. You’re about to run your very first Ruby script. In the terminal, type this:
$ ruby hello.rb
And boom! Your program will run, and you should see this appear on your screen:
Hello, World!
Congratulations! That’s your first Ruby program. It might seem super simple, but it’s a big deal. Not only does this program confirm that your Ruby environment is all set up and ready to go, but it also gives you your first taste of how Ruby works. You’ve just taken the first step in your Ruby journey.
Now that your environment is working smoothly, you can dive deeper into Ruby, explore more advanced concepts, and start building some really cool projects. The world of Ruby programming is wide open, and with your setup ready to go, you’re all set to create some powerful Ruby applications. Ready to keep coding? Let’s do this!
For more information, you can refer to the official Ruby Documentation.
Conclusion
In conclusion, setting up a Ruby development environment on Windows 10 using WSL and RVM opens up a powerful way to run Ruby with Linux tools. By following this guide, you’ve learned how to install Bash, configure the Ruby Version Manager (RVM), and ensure everything is running smoothly with a simple Ruby program. This setup not only streamlines your development process but also provides a seamless way to work with Linux-like tools on a Windows machine. As Ruby continues to evolve, keeping your environment up to date with the latest versions of Ruby and RVM will help you stay ahead of the curve. With these tools in place, you’re now ready to dive deeper into Ruby development and explore more complex projects.