Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

How to Install Ruby on Rails: A Comprehensive Guide for macOS, Windows, and Linux

Save for later
  • 600 min read
  • 2024-10-25 08:36:31

article-image

This article is an excerpt from the book, https:// www.digitalocean.com/community/tutorials/how-to-install-ruby-onrails-with-rbenv-on-macos

Installing Ruby on Rails on Windows 

Follow these steps to install Ruby on Rails on Windows: 

1. To set up our local environment, first, we must install Git for Windows. We can download the package from https://gitforwindows.org/. 

Once downloaded, we can run the installer; it should open the installer application: 

 

Figure 7.4 – Git SDK installation location 

This package might take a while to complete as it has to download other additional packages but it will do so on its own. Please be patient. Once this package has finished installing the SDK, it will open a Git Bash console, which looks similar to Windows PowerShell. We can close this Git Bash console window and open another Windows PowerShell. 

Once we have the new window open, we must type the following command: 

new-item -type file -path $profile -force 

This command will help us create a Windows PowerShell profile, which will allow us to execute commands every time we open a Windows PowerShell console. Once we’ve run the previous command, we may also close the Windows PowerShell window, and move on to the next step. At this point, we will install rbenv, which allows us to install multiple versions of Ruby. However, this program wasn’t created for Windows, so its installation is a little different than in other operating systems. 

Let’s open a browser and go to the rbenv for Windows web page: https://github.com/ ccmywish/rbenv-for-windows

On that page, we will find instructions on how to install rbenv, which we will do now. 

Let’s open a new Windows PowerShell and type the following command: 

$env:RBENV_ROOT = "C:\Ruby-on-Windows " 

This command will set a special environment variable that will be used for the rbenv installation. 

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime

6. Once we’ve run this command, we must download the rest of the required files with the following command: 

iwr -useb "https://github.com/ccmywish/rbenv-for-windows/raw/ main/tools/install.ps1" | iex 

7. Once this command has finished downloading the files from GitHub, modify the user’s profile with the following command from within the Windows PowerShell: 

notepad $profile 

This will open the Notepad application and the profile we previously set. 

On the rbenv-for-windows web page, we can see what the content of the file should be. Let’s add it with Notepad so that the profile file now looks like this: 


$env:RBENV_ROOT = "C:\Ruby-on-Windows"

& "$env:RBENV_ROOT\rbenv\bin\rbenv.ps1" init

Save and close Notepad, and close all Windows PowerShell windows that we may have open. We should open a new Windows PowerShell to make these changes take effect. As this is the first time rbenv is running, our console will automatically install a default Ruby version. This might take a while and will put our patience to the test. Once the process has finished, we should see an output similar to this one: 

https://www.ruby-lang.org/en/documentation/installation/. 

Conclusion 

In conclusion, installing Ruby on Rails varies across operating systems, but the general process involves setting up a version manager like rbenv, installing Ruby, and then using Bundler to manage gems. Whether you're on macOS, Windows, or Linux, each system has specific steps to ensure Rails and its dependencies run smoothly. By following the detailed instructions for your platform, you'll have your development environment ready for Rails in no time. For further guidance and platform-specific nuances, refer to the official documentation and resources linked throughout this guide. 

Author Bio

Bernard Pineda is a seasoned developer with 20 years of web development experience. Proficient in PHP, Ruby, Python, and other backend technologies, he has taught PHP and PHP-based frameworks through video courses on platforms like LinkedIn Learning. His extensive work with Ruby and Ruby on Rails, along with curiosity in frontend development and game development, bring a diverse perspective to this book. Currently working as a Site Reliability Engineer in Silicon Valley, Bernard is always seeking new adventures.

Modal Close icon
Modal Close icon

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant