banner



How To Install Gems In Windows

Ruby is a well-established and well-regarded programming language. One time upon a fourth dimension, installing Ruddy on Windows came with problems, but things accept come a long way. Today, there's no reason someone couldn't write Carmine lawmaking on whatsoever platform.

First released in the mid-1990s, Ruby'due south popularity soared with the release of Red on Track in 2005. Blood-red is primarily an object-oriented programming language (OOP), but it offers powerful aspects of the functional programming paradigm too. Information technology's less verbose than many other languages, offer a concise and straightforward syntax. This simplicity makes it a good language to start with. The popular Ruby-red on Runway spider web framework too powers many large websites, meaning Ruby is here to stay.

Allow's take a look at how to gear up a functioning Ruby environment on your Windows calculator.


New call-to-action


Getting some respect

Cherry'southward difficulties on Windows stem from the fact that it's very different, under the covers, from both Linux and macOS. Those two operating systems have similar "toolchains" because both are based on Unix. This means that they can use the aforementioned compiler, shared library organization, and other tools to build the Ruddy interpreter and Ruby libraries, which are called "RubyGems."

Ruby is an open-source linguistic communication written by volunteers. It was developed on Unix-based computers, so making the language piece of work at that place came first. There's always been an effort to make it piece of work on Windows too, but the Unix-like environments got priority.

For many years, trying to develop Carmine code on a Windows computer meant dealing with issues that someone using a Mac or Linux computer wouldn't face. To a certain extent, that'southward still true. When seeking assist for a trouble you run into, yous'll likely detect fewer search results for Windows. Plus, you may find that less common libraries don't fifty-fifty offer a Windows version.

And if you're planning on deploying your code, you should remember near what that platform will exist. For example, if you want to write a Ruby on Runway spider web application, you'll likely be deploying it onto a Linux web server. It's always best to continue the development surroundings as close as possible to the product surroundings so that you don't get whatever surprises when your code goes live.

Two ways to become there

One of the nearly surprising and pleasant developments in the software world in recent years has been Microsoft warming up to open source. The tech giant at present has over 2,400 repositories on GitHub, and the description on their GitHub contour says "open up-source, from Microsoft with love." Their open up-source projects include the popular Visual Studio Code programming text editor. They've likewise embraced open source by bringing Linux to Windows!

That'due south right, Windows x allows you to install a Linux "subsystem" on the aforementioned estimator. This means you can install and run Linux applications. This also means that y'all tin can utilize Linux package managers to install the traditional Cherry environs. It's called the Windows Subsystem for Linux, and we'll comprehend how to get a working Red installation with the approach below.

Withal, if you lot have a computer running an older version of Windows, that selection isn't available to you. But fearfulness not. At that place's nevertheless agile development on Ruby for Windows, including correct up to the nearly contempo version of Ruby. This project is chosen RubyInstaller, and it works its magic by using the MSYS2 system for providing Unix-similar libraries on Windows every bit well as MinGW (Minimal Gnu for Windows), which is a large library of Unix-similar packages that work on Windows.

But yous don't need to worry about those details. RubyInstaller provides you with a straightforward, mostly GUI-based experience to get Crimson up and running on your older Windows machine. Let's await at this pick first.

Using RubyInstaller

To use RubyInstaller, you need to first download information technology from their downloads page. Find that the list of options has "with Devkit" and "without Devkit" sections. The Devkit versions install the MSYS2 system, which will be required if you demand to install RubyGems that require compilation. If you're just going to play around with apparently one-time Cherry, you lot might be able to go abroad with the non-Devkit version. But why limit yourself? If y'all want to work on a Reddish on Track app, you'll definitely need to compile gems, then you need the Devkit.

Ruby Installer for Windows

Also note that there are various Crimson versions available, and in that location are both x86 and x64 packages. Currently, there's an arrow pointing at the 2.five.five-one (x64) bundle. That'south considering it'due south still the preferred Ruby version for most people. Red ii.half-dozen.3 is still fairly new, so it won't have as many gems bachelor. Besides, equally information technology says on the page, "the 32 fleck (x86) version is recommended only if custom 32-fleck native DLLs or COM objects have to be used." You should stick with x64.

Download that and run information technology to become started. Y'all'll first demand to have the license agreement.

Ruby Install Windows License Agreement

On the next screen, be certain to check the MSYS2 development toolchain pick:

Ruby Installer Select Components

Then click "Next" and grab a cold 1. Information technology takes a few minutes to install everything.

Tooling up with the MSYS2 toolchain

Once you've done that, some other of import checkbox appears on the terminal screen of the installer: "Run 'ridk install' to ready MSYS2." The GUI installer won't do that part for you, and so apply this checkbox to kick that off next:

Install Ruby on Windows setup

Installing the development toolchain is a command-line procedure, so a concluding window volition open to consummate this part:

Ruby Installer for Windows

This "ridk install" control asks which components y'all desire to install. It's fine to merely hit "Enter" to accept the default. This will install the base of operations MSYS2 organization, bank check for updates to it, and so install the development toolchain.

Once that'south rolling, you'll run across a lot of output streaming by. It takes at least every bit long as installing Ruby did. When y'all've done that, y'all should encounter the message "install MSYS2 and MinGW development toolchain succeeded." Oddly enough, that leaves you at the same install prompt. Just hit "Enter" again to go out of that. The terminal window will close.

Ready to rock Cherry-red on Windows!

In order to check out your fresh Ruby install, you need to open a final window again. Yous can practice so by opening the Windows menu and typing "cmd" in the search box. At the command prompt, blazon "ruby -v" and hitting "Enter." You should come across something similar this:

Ruby Installer Windows Command Prompt

And running the command "gem list" volition show you what RubyGems came with your fresh install:

Ruby Gem List Windows

You tin too run "irb," the interactive Ruby shell:

Ruby Shell Windows

Try out some Ruby!

Ready for Rails?

You can then go on to install Ruby on Runway, which is a RubyGem. However, note that Runway is generally used to develop database-backed spider web applications. That means that it needs a database server to talk to. Then when you try to generate a new Rails application without whatsoever options specified, you'll get an mistake because, past default, Runway tries to apply the SQLite database engine. The Track team chose SQLite equally the default because it's often already installed on Mac or Linux and because it doesn't need a database server procedure. Information technology stores its data in a file on disk.

About serious applications utilise a more robust database server, similar MySQL or PostgreSQL. So you may want to install one of those on your Windows motorcar then generate your Rails app with the option to specify that database driver.

Try Stackify'southward free code profiler, Prefix, to write better code on your workstation. Prefix works with .Cyberspace, Java, PHP, Node.js, Ruby, and Python.

Using the Windows Subsystem for Linux

As mentioned previously, with Windows ten, Microsoft started offering a standard way to run a Linux command line on Windows computers. This is called the Windows Subsystem for Linux (WSL), and it'due south adequately easy to get started with. Information technology is also a good manner to get working with Scarlet on Windows. You fifty-fifty go your choice of Linux distro. If you're non too familiar with Linux, a "distro" is the distribution of Linux. Common distros include Cerise Lid, CentOS, Debian, Ubuntu, etc. For this tutorial, we're going to apply Ubuntu.

To utilise the WSL, you first need to enable it. At that place are tutorials online that tell you lot how to do this past running a command in an admin console (e.g., "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux") merely you lot don't have to bother with that. It's a standard Windows feature now, then yous can plough information technology on in the Windows control panel.

In one case y'all take the control panel open up, cull "Programs" so "Turn Windows features on or off." Roll downwards to the bottom of the listing and cheque the checkbox side by side to "Windows Subsystem for Linux," so click "OK." And then reboot the calculator.

Hi Linux!

After your calculator has rebooted, you can install the Linux distro of your choice from the Microsoft Store. We're going to utilize Ubuntu 18.04 LTS (which stands for "long-term support"):

In one case that's finished installing, you can quit the store application. Your spiffy new Ubuntu command line will exist available equally an app from the Windows bill of fare:

Running that opens a terminal window and kicks off the setup steps for this mini Linux install. In that location are but 2 steps: enter a username and a password. They can be the aforementioned as your Windows username and password or different. After setting that up, you should take a working Bash prompt!

If you're not familiar with Fustigate, information technology'south the Bourne Again Beat, the nigh common terminal shell program in Unix/Linux. There are lots of tutorials online virtually how to use the Linux command line. A few commands are "ls" to list files/directories in the electric current directory, "cd <path>" to alter to a given directory, and "pwd" to impress your electric current directory path.

From here on, you could probably follow any tutorial on installing Scarlet on Ubuntu. Only I won't leave yous hanging. Read on for specific steps to Ruby joy.

Installing Cherry-red on the WSL

The easiest manner to install Ruby on Ubuntu is with a bundle manager. And for Ubuntu, that ways "apt." You need to be an administrator—or every bit information technology'southward called in the Unix globe, a "superuser"— to install packages. The way to run a control as the superuser is by putting the command "sudo" ("SUperuser Practice") before it.

Before we tackle installing Cerise though, permit's make sure our new Ubuntu install is up to date. Run the post-obit in your Bash terminal:

sudo apt update && sudo apt dist-upgrade && sudo apt autoremove && sudo apt clean

This volition fetch a bunch of packages so inquire yous to make sure you want to install them. Y'all can just striking enter to say aye. Then comes more waiting! It'southward probable that you will take dozens of updates to install.

Once that'south done, y'all may get another question asking you if you lot want to remove some packages. Become ahead and hit "Enter" to say yeah.

One time you have your prompt dorsum, y'all're set to install Cherry-red! Do that with this simple control:

sudo apt install ruby-full

This does some dependency-checking and shows you what you lot need to install to get Ruby working:

As always, striking "Enter" to accept, and abroad we go. At that place certain is a lot of waiting involved in installing software, isn't there? But once apt has done its magic, nosotros'll have a working Crimson two.5.i install in our Linux Subsystem. As with RubyInstaller, you can verify the Ruby install by running "ruby -v":

And yous can cheque the RubyGems installed with "precious stone list":

This is almost the same list every bit we got with RubyInstaller. And again, you can run "irb" to play around with Ruby.

Bonus points!

Let's go a fleck farther with our WSL Cerise install and run into what it takes to get Ruby on Rail prepare up. This Ubuntu install doesn't yet have the power to compile gems, and Rail volition demand that. In particular, Rails wants to utilize the Nokogiri gem for parsing HTML, and that requires compiling its native extensions. The Nokogiri installation page gives u.s.a. a list of apt packages to install to set up for Nokogiri: "build-essential, patch, ruby-dev, zlib1g-dev, and liblzma-dev."

However, we're likewise going to accept the same problem with needing SQLite to utilize the default Rail app generator. Luckily, apt has an SQLite library that fits the bill: libsqlite3-dev. Finally, Rails uses Node.js to exercise its JavaScript and asset packaging, and so we want apt to install that as well.

Permit's add all that to the apt command Nokogiri gave united states and run it:

sudo apt install build-essential patch ruby-dev zlib1g-dev liblzma-dev libsqlite3-dev nodejs

Later on that long listing of packages is installed, y'all tin run "gem install rails." Windows Defender will probably make sure you're okay with Ruby making network calls:

Go ahead and allow it and scout the gems fly by. Compiling Nokogiri will take a bit of time also.

WSL file system oddities

With Rail installed, you are ready to generate your first Rails app. But before we do that, you should know something about working with files in the Linux Subsystem.

Running the WSL concluding puts you in your WSL home directory. If you open an Ubuntu terminal and run "pwd," you volition see "/dwelling/<your username>." This is basically a make-believe directory living within the WSL application. You can create a file there and so search for it in Windows Explorer. It won't notice it.

To be able to piece of work on your Ruby code with a Windows GUI text editor (like VSCode), you lot should put your code someplace Windows Explorer can find it.

Your figurer's C drive is visible in the WSL at the path "/mnt/c." ("mnt" is a Linux convention for the location where drives are mounted and "c" refers to your C bulldoze). So if y'all run "cd /mnt/c," you'll be at the root of the C drive. You can create a directory for your work hither, either through Windows Explorer or by running "mkdir ruby_work" in the Bash terminal.

Rolling on Rail!

Y'all can so generate a new Rails app with "rails new <app name>." Rail volition create a directory named with your app name and an initial project structure inside. It volition also install gems just for your app.

In the early years of Rails, developers institute that information technology was problematic working on several Ruby or Rails apps on the same machine and needing different versions of the aforementioned gems per app. Bundler came forth to solve this problem. You list your app'south gems in a Gemfile and and so run the command "bundle install" to install those gems just for that app.

Start the development server past running "rail s" in the app directory. And then you tin open a browser and go to http://localhost:3000 and encounter the default Rails starting time folio!

Rocking the Ruby

Whichever approach you lot took, yous should now have a functioning Ruddy install on your Windows machine. Note that these aren't the only two means to become Ruby working on your machine. Yous tin as well use a virtual auto application like VirtualBox or VMWare to create a Linux virtual machine. This would be similar to the WSL approach, but yous could install a desktop Linux distro so that you lot can interact with the UI. Vagrant uses VM software, but it allows yous to choose from set up-to-get machine images and has a way to make the code on your Windows machine visible to the VM.

Another thing to consider as y'all sheet away on your Ruby-red journey: what should you do when you wind up working on multiple Carmine projects that require different versions of Ruby? To practise this, you can use a Scarlet version manager similar RVM or RBenv.

Finally, once yous've built something with Scarlet, yous're going to want to keep an centre on its performance, spotter for errors, and debug product problems. For this, you should take a await at Retrace. It tin help you lot continue an eye on your code from top to bottom!

Start Free Trial
  • About the Author
  • Latest Posts

Source: https://stackify.com/install-ruby-on-windows-everything-you-need-to-get-going/

Posted by: hubbardhithorable.blogspot.com

0 Response to "How To Install Gems In Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel