How to Install Rails 6.1 on Windows with Winget
Introduction
This guide is aimed at programming beginners who want to work with Ruby and Rails. If you’re a power user, skip to the end for the TL;DR section.
It assumes you’re on Windows 10 and have nothing pre-installed to work with Ruby and/or Rails, so this guide starts from scratch.
Preparation
Go to the start menu and open Windows PowerShell
. It could also say (x86)
at the end, but be sure not to select the ISE
entry.
Now we check whether the winget
package manager is already installed. For this, type winget
into the PowerShell windows and hit Enter:
This probably looks like the image above. It prints out red text that tells you that winget
is not installed, so let’s install that first. You should close the PowerShell window now. If it does not show red text, but instead information about winget, then winget is already installed. In that case you can skip the installation and go directly installing packages.
Install winget
Go to https://github.com/microsoft/winget-cli/releases/latest and download the file that ends in .msixbundle
. Once it’s downloaded, double-click the file. It will ask you to “Update App Installer”, so you click the “Update” button. This should only take a few seconds and should show you a mostly white screen with the message: “For proper function of the app, try to launch a Windows app package”. This means you successfully installed the winget package manager and can close this window. Close the previous PowerShell window if it is still open.
Installing the packages
Open the Windows PowerShell
as an administrator and hit “Yes” on the following User Account Control window:
Now enter the winget
command and hit Enter. You should see the following output:
This means winget was installed successfully. We’re now going to install the first bunch of packages, namely NodeJS, Yarn, Git, Ruby.
Copy and paste the following into PowerShell and hit Enter:
winget install node; winget install yarn; winget install git; `
winget install RubyInstallerTeam.RubyWithDevKit
This will take a few minutes to install the packages. Small installation windows will pop up during this process but you don’t have to do anything at this point. At the end it should look like this:
Installing Ruby development tools and Rails
Now we have to close the PowerShell window and re-open it again as an administrator, as we have done before.
Enter this and hint enter:
ridk install 3
This takes a while, after it’s done we have to close the PowerShell window and re-open it again. This time you can open it by just clicking on the start menu entry, you don’t need to be an administrator.
Create a folder called “rails” in your home folder. You can also give it a different name, but we will use “rails” here. Then, go back to your PowerShell, enter “cd “ (the space afterwards is important!), drag the “rails” folder into the PowerShell window, drop it and then hit enter like this:
cd
here stands for “change directory”, we told PowerShell to navigate to this directory.
Copy and paste this into PowerShell and hit Enter:
gem install rails --version "~> 6.1" --no-doc
Hint: at the time of writing this (August 2021), 6.1 was the lastest version. You might also want to just try gem install rails --no-doc
and install the latest version.
After that, enter:
rails new myapp
This also takes a few minutes, most probably longer than installing the packages. At the end, it should look like this:
If you see this, Rails has been successfully installed. We also created a small Rails application called myapp
.
Starting the Rails server
You can now change to this app and start the Rails server:
cd myapp
followed by:
bundle exec rails server
You should copy and paste both commands and hit Enter for both.
It should now look like this:
This means the Rails server was started successfully. You can follow the instructions and open your Rails app in the browser by going to http://localhost:3000. You should see this:
Congratulations! You successfully installed Rails and created your first app.
Bonus level: installing an editor
To comfortably work with your Rails project, I recommend to install an editor. A popular editor is VS Code. You can install it via PowerShell:
winget install vscode
After this, close and re-open the PowerShell window, navigate again to your rails
folder, then to your myapp
folder like we did in “Starting the Rails server”, then enter:
code .
Now VS Code starts and opens your myapp
project. You’re now ready to work on your app.
Closing words
I hope this guide was helpful to you. Reach out via Twitter if you liked it and/or if you had any issues with it. Feel free to share it. Cheers!
TL;DR
For power users, the short summary:
- Check whether
winget
is installed, if not install the msixbundle from here - Open PowerShell as administrator and enter:
winget install node; winget install yarn; winget install git; winget install RubyInstallerTeam.RubyWithDevKit
- Close Powershell, re-open as administrator: enter:
ridk install 3
- Close PowerShell, re-open as normal user, enter:
gem install rails --version "~> 6.1" --no-doc; rails new myapp
- A new app called myapp has been created, start the Rails server:
cd myapp; bundle exec rails server
- Open your app: http://localhost:3000