banner



How To Install Gems In Windows

Ruby is a well-established and well-regarded programming language. Once upon a fourth dimension, installing Ruby on Windows came with problems, but things have come a long way. Today, there's no reason someone couldn't write Cherry-red code on any platform.

Outset released in the mid-1990s, Ruby's popularity soared with the release of Ruby on Track in 2005. Ruddy is primarily an object-oriented programming language (OOP), but it offers powerful aspects of the functional programming paradigm likewise. 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 pop Ruby on Track web framework likewise powers many large websites, meaning Ruby is here to stay.

Permit's take a look at how to set up upward a operation Carmine environment on your Windows reckoner.


New call-to-action


Getting some respect

Ruby's difficulties on Windows stem from the fact that it's very unlike, under the covers, from both Linux and macOS. Those 2 operating systems have similar "toolchains" because both are based on Unix. This means that they can employ the same compiler, shared library system, and other tools to build the Carmine interpreter and Reddish libraries, which are called "RubyGems."

Ruby is an open-source language written by volunteers. It was developed on Unix-based computers, so making the language work in that location came beginning. There's ever been an effort to go far piece of work on Windows as well, but the Unix-like environments got priority.

For many years, trying to develop Ruby code on a Windows reckoner meant dealing with issues that someone using a Mac or Linux estimator wouldn't face. To a certain extent, that's still truthful. When seeking aid for a problem yous meet, you'll likely discover fewer search results for Windows. Plus, you may find that less mutual libraries don't even offer a Windows version.

And if y'all're planning on deploying your lawmaking, y'all should think about what that platform will be. For example, if you want to write a Cherry on Runway web application, y'all'll probable be deploying information technology onto a Linux spider web server. It's e'er best to keep the evolution environment as shut as possible to the product environment so that you don't get any surprises when your code goes alive.

2 ways to go at that place

I of the most surprising and pleasant developments in the software earth in recent years has been Microsoft warming upward to open source. The tech behemothic now has over 2,400 repositories on GitHub, and the description on their GitHub profile says "open-source, from Microsoft with love." Their open-source projects include the popular Visual Studio Lawmaking programming text editor. They've also embraced open up source by bringing Linux to Windows!

That's right, Windows 10 allows you lot to install a Linux "subsystem" on the same computer. This means yous tin can install and run Linux applications. This likewise means that you tin can employ Linux package managers to install the traditional Ruby surround. It'due south called the Windows Subsystem for Linux, and we'll cover how to get a working Ruby installation with the arroyo below.

However, if you lot have a computer running an older version of Windows, that selection isn't available to you lot. But fear not. There'due south still active development on Red for Windows, including right up to the most recent version of Cerise. This project is called RubyInstaller, and it works its magic by using the MSYS2 system for providing Unix-like libraries on Windows likewise as MinGW (Minimal Gnu for Windows), which is a big library of Unix-like packages that piece of work on Windows.

Simply yous don't demand to worry almost those details. RubyInstaller provides you lot with a straightforward, generally GUI-based experience to get Ruby upwardly and running on your older Windows machine. Let's expect at this option first.

Using RubyInstaller

To use RubyInstaller, you demand to first download information technology from their downloads folio. Detect 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 need to install RubyGems that require compilation. If yous're just going to play around with plain old Carmine, y'all might be able to get abroad with the non-Devkit version. Only why limit yourself? If you want to work on a Ruby-red on Rails app, you lot'll definitely need to compile gems, so y'all need the Devkit.

Ruby Installer for Windows

Too note that at that place are diverse Ruby versions available, and there are both x86 and x64 packages. Currently, there's an arrow pointing at the 2.5.5-1 (x64) package. That'southward because it's notwithstanding the preferred Carmine version for most people. Cerise 2.half dozen.3 is still fairly new, then information technology won't have every bit many gems available. Likewise, equally information technology says on the page, "the 32 bit (x86) version is recommended only if custom 32-bit native DLLs or COM objects accept to exist used." You should stick with x64.

Download that and run it to go started. You'll first need to have the license agreement.

Ruby Install Windows License Agreement

On the next screen, exist sure to check the MSYS2 development toolchain option:

Ruby Installer Select Components

And then click "Adjacent" and grab a cold i. Information technology takes a few minutes to install everything.

Tooling upward with the MSYS2 toolchain

Once you've done that, some other important checkbox appears on the concluding screen of the installer: "Run 'ridk install' to fix upward MSYS2." The GUI installer won't do that part for you, so employ this checkbox to kick that off side by side:

Install Ruby on Windows setup

Installing the evolution toolchain is a command-line procedure, so a last window volition open up to complete this part:

Ruby Installer for Windows

This "ridk install" control asks which components y'all desire to install. Information technology'due south fine to just striking "Enter" to accept the default. This volition install the base of operations MSYS2 system, bank check for updates to it, then install the development toolchain.

Once that's rolling, you'll see a lot of output streaming past. Information technology takes at least every bit long equally installing Ruby did. When you've done that, you should see the bulletin "install MSYS2 and MinGW development toolchain succeeded." Oddly enough, that leaves you at the same install prompt. Just hit "Enter" once again to leave of that. The terminal window will shut.

Gear up to rock Ruby on Windows!

In order to bank check out your fresh Ruby install, you need to open a last window again. You can exercise then by opening the Windows bill of fare and typing "cmd" in the search box. At the command prompt, type "ruddy -v" and striking "Enter." You should meet something like this:

Ruby Installer Windows Command Prompt

And running the command "precious stone listing" will show you what RubyGems came with your fresh install:

Ruby Gem List Windows

You tin also run "irb," the interactive Ruby-red trounce:

Ruby Shell Windows

Try out some Cerise!

Ready for Runway?

You tin can then become on to install Red on Rails, which is a RubyGem. However, notation that Rails is generally used to develop database-backed web applications. That means that it needs a database server to talk to. Then when you try to generate a new Runway application without any options specified, yous'll get an error because, past default, Runway tries to use the SQLite database engine. The Track squad chose SQLite as the default because it'southward oftentimes already installed on Mac or Linux and because it doesn't need a database server process. It stores its data in a file on disk.

Virtually serious applications employ a more than robust database server, like MySQL or PostgreSQL. So you lot may want to install one of those on your Windows motorcar and and then generate your Rails app with the option to specify that database driver.

Endeavor Stackify'southward complimentary code profiler, Prefix, to write meliorate lawmaking on your workstation. Prefix works with .Net, Java, PHP, Node.js, Carmine, and Python.

Using the Windows Subsystem for Linux

Every bit mentioned previously, with Windows ten, Microsoft started offer a standard style to run a Linux command line on Windows computers. This is called the Windows Subsystem for Linux (WSL), and it's fairly easy to get started with. It is besides a expert way to go working with Ruby on Windows. Yous fifty-fifty get your pick of Linux distro. If you're not too familiar with Linux, a "distro" is the distribution of Linux. Common distros include Red Hat, CentOS, Debian, Ubuntu, etc. For this tutorial, we're going to use Ubuntu.

To use the WSL, you first need to enable it. There are tutorials online that tell you how to practise this past running a command in an admin panel (e.g., "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux") but you don't take to bother with that. It'due south a standard Windows feature now, and so yous can turn it on in the Windows control console.

Once yous have the control panel open, choose "Programs" and so "Turn Windows features on or off." Gyre down to the bottom of the list and check the checkbox next to "Windows Subsystem for Linux," and so click "OK." And so reboot the calculator.

Hullo Linux!

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

Once that's finished installing, yous can quit the store application. Your spiffy new Ubuntu control line will be available equally an app from the Windows menu:

Running that opens a last window and kicks off the setup steps for this mini Linux install. At that place are only 2 steps: enter a username and a password. They tin can be the same equally your Windows username and password or different. After setting that upwards, you should have a working Bash prompt!

If you're not familiar with Bash, it'southward the Bourne Over again Shell, the most common concluding 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 current directory, "cd <path>" to change to a given directory, and "pwd" to print your 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-red joy.

Installing Ruby on the WSL

The easiest manner to install Ruby on Ubuntu is with a package director. And for Ubuntu, that means "apt." You lot need to exist an administrator—or as information technology's called in the Unix world, a "superuser"— to install packages. The way to run a control as the superuser is past putting the command "sudo" ("SUperuser Practice") before it.

Earlier we tackle installing Ruby though, let's brand sure our new Ubuntu install is upwards to engagement. Run the following in your Bash terminal:

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

This will fetch a bunch of packages so inquire you to make certain you want to install them. Y'all can only hit enter to say yes. Then comes more than waiting! It'due south likely that you lot will have dozens of updates to install.

One time that'southward washed, you may become another question asking you if you lot desire to remove some packages. Go ahead and hitting "Enter" to say yes.

Once y'all have your prompt back, you lot're ready to install Ruby! Practice that with this uncomplicated command:

sudo apt install carmine-full

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

Equally always, striking "Enter" to accept, and away we get. There sure is a lot of waiting involved in installing software, isn't in that location? Simply once apt has washed its magic, we'll have a working Ruby 2.v.1 install in our Linux Subsystem. As with RubyInstaller, you can verify the Ruby-red install by running "reddish -v":

And you can bank check the RubyGems installed with "gem list":

This is nearly the same listing as we got with RubyInstaller. And again, y'all can run "irb" to play around with Red.

Bonus points!

Let's go a bit further with our WSL Crimson install and come across what it takes to go Ruby on Rails fix. This Ubuntu install doesn't yet have the ability to compile gems, and Runway volition need that. In particular, Rail wants to apply the Nokogiri precious stone for parsing HTML, and that requires compiling its native extensions. The Nokogiri installation page gives us a list of apt packages to install to set for Nokogiri: "build-essential, patch, ruby-dev, zlib1g-dev, and liblzma-dev."

However, we're also going to take the same trouble with needing SQLite to apply the default Rails app generator. Luckily, apt has an SQLite library that fits the bill: libsqlite3-dev. Finally, Rails uses Node.js to do its JavaScript and asset packaging, so we want apt to install that every bit well.

Allow's add all that to the apt control Nokogiri gave us and run it:

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

Afterward that long list of packages is installed, you can run "jewel install rails." Windows Defender will probably make certain you're okay with Ruby making network calls:

Get ahead and allow it and spotter the gems fly past. Compiling Nokogiri will take a flake of time as well.

WSL file organisation oddities

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

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

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

Your reckoner'due south 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 drive). So if you run "cd /mnt/c," you'll exist at the root of the C drive. Y'all tin can create a directory for your work here, either through Windows Explorer or by running "mkdir ruby_work" in the Bash terminal.

Rolling on Rails!

You tin can then generate a new Rails app with "rails new <app name>." Rails will create a directory named with your app name and an initial project structure inside. Information technology volition also install gems just for your app.

In the early years of Runway, developers found that it was problematic working on several Cherry or Runway apps on the same motorcar and needing unlike versions of the same gems per app. Bundler came along to solve this problem. You list your app's gems in a Gemfile and then run the command "parcel install" to install those gems simply for that app.

Showtime the evolution server by running "runway s" in the app directory. Then you can open a browser and go to http://localhost:3000 and come across the default Runway start page!

Rocking the Ruddy

Whichever approach you took, you should now have a functioning Ruby install on your Windows machine. Notation that these aren't the only two ways to get Ruby working on your machine. You can too utilize a virtual car awarding like VirtualBox or VMWare to create a Linux virtual machine. This would be like to the WSL approach, but you could install a desktop Linux distro then that you can interact with the UI. Vagrant uses VM software, simply it allows you lot to cull from fix-to-go motorcar images and has a way to brand the lawmaking on your Windows machine visible to the VM.

Another matter to consider equally yous sail away on your Ruby-red journey: what should you practise when you wind up working on multiple Ruby projects that crave different versions of Ruby? To practice this, you can use a Ruby version director like RVM or RBenv.

Finally, in one case yous've built something with Carmine, yous're going to desire to keep an eye on its performance, watch for errors, and debug production issues. For this, you should have a expect at Retrace. It can assist you continue an center on your lawmaking from top to bottom!

Start Free Trial
  • Nearly the Writer
  • Latest Posts

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

Posted by: tayloryournished.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