Install Ruby On Rails on
Windows 11
A guide to setting up a Ruby on Rails development environment
Overview
This will take about 30 minutes.
In this guide, we will be installing Ruby on Rails on Windows 11.
We're going to use the Windows Subsystem for Linux (WSL) to accomplish this. This allows you to install a Linux distribution natively on Windows without a virtual machine.
Ruby on Rails will always be deployed to a Linux server, so it's best for us to use the same for development.
Installing the Windows Subsystem for Linux
Windows allows you to run various Linux operating systems inside of Windows similar to a virtual machine, but natively implemented. We'll use this to install Ruby and run our Rails apps.
You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.
Open Powershell and run:
wsl --install -d Ubuntu
Reboot your computer to finish the installation.
Once initial setup is finished, you will be prompted to create a username and password for your Ubuntu install.
You can search for "Ubuntu" in the Windows Start Menu anytime to open the Ubuntu terminal.
Congrats! You now have Ubuntu installed on Windows with WSL. You'll use this to run your Rails server and other processes for development.
Installing Ruby
The first step is to install dependencies for compiling Ruby.
Open your Terminal and run the following commands to install them.
sudo apt-get update
sudo apt install build-essential rustc libssl-dev libyaml-dev zlib1g-dev libgmp-dev
Next, we'll install Ruby using a version manager called Mise. This allows you to easily update Ruby and switch between versions anytime.
curl https://mise.run | sh
echo 'eval "$(~/.local/bin/mise activate)"' >> ~/.bashrc
source ~/.bashrc
Then install Ruby with Mise:
mise use --global ruby@3
Confirm that Ruby is installed and works:
ruby --version
#=> 3.3.5
You also want to ensure you're using the latest version of Rubygems.
gem update --system
Optionally, if you plan to use Node.js for handling assets, you can use Mise to install Node as well.
mise use --global node@22.11.0
node -v
#=> 22.11.0
Configuring Git
We'll be using Git for our version control system so we're going to set it up to match our Github account. If you don't already have a Github account, make sure to register. It will come in handy for the future.
Replace my name and email address in the following steps with the ones you used for your Github account.
git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"
ssh-keygen -t ed25519 -C "YOUR@EMAIL.com"
The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.
cat ~/.ssh/id_ed25519.pub
Once you've done this, you can check and see if it worked:
ssh -T git@github.com
You should get a message like this:
Hi excid3! You've successfully authenticated, but GitHub does not provide shell access.
Installing Rails
Choose the version of Rails you want to install:
gem install rails -v 8.0.0
Now that you've installed Rails, you can run the rails -v
command to make sure you have everything installed correctly:
rails -v
# Rails 8.0.0
If you get a different result for some reason, it means your environment may not be setup properly.
Setting Up PostgreSQL
For PostgreSQL, we're going to add a new repository to easily install a recent version of Postgres.
sudo apt install postgresql libpq-dev
sudo service postgresql start
You'll need to start postgresql each time you load your WSL environment.
The postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replace chris
with your username.
sudo -u postgres createuser chris -s
# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password chris
Final Steps
Let's create your first Rails application on Windows!
rails new myapp -d postgresql
#### Or if you want to use MySQL
rails new myapp -d mysql
# Then, move into the application directory
cd myapp
# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified
# Create the database
rake db:create
rails server
You can now visit http://localhost:3000 to view your new website!
Getting an "Access Denied" error?
If you received an error that said Access denied for user 'root'@'localhost' (using password: NO)
then you need to edit the config/database.yml
file to match the database username and password.
Editing Code
Install VS Code on Windows and install the WSL extension. This will allow you to edit code in Windows but run commands and extensions in WSL. Read more about Developing in WSL.
That's it! Let us know in the comments below if you run into any issues or have any other protips to share!