Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Ruby Programming/Installing Ruby

From Wikibooks, open books for an open world
<Ruby Programming

← Overview| Ruby editors →


The first step to get started in Ruby development is setting up your local environment. Due to differences between various operating systems we will cover multiple of them. If you are already able to use a terminal emulator and know how to install Ruby yourself, you can skip this chapter (after you installed Ruby). Otherwise we will guide you through the process of installing Ruby on your computer.

Terminal emulators

[edit |edit source]

Knowing how to use a terminal emulator is very useful if you are programming. Usually it will provide the most straightforward access to commands and applications instead of hiding it behind graphical interfaces. On the other hand they are often daunting to beginners since they are often perceived to require a deep understanding of a computer when in fact often only knowing the very basics is already enough to get started.

Unix-like operating systems

[edit |edit source]
Screenshot of xterm running Bash
Main article:Linux Guide/Using the shell

One of the most commonly used shells in the Unix-like operating systems (i.e. macOS, GNU/Linux, BSD) is theBash shell, in fact it is very often the default shell. To start a session you will often use a terminal emulator, which allow you to use a terminal session at the same time as other graphical applications.It doesn't really matter, which terminal emulator you use, generally you want one that has color and Unicode support. In macOS you can use Terminal.app which you can find under Applications > Utilities. A popular alternative isiTerm. On most Linux distributions you will usually be provided with at least one terminal emulator by default, otherwise you might want to try Terminator, Konsole, rxvt-unicode or something different.

When you open a new window or tab in your terminal emulator of choice you will be shown your prompt. What it looks like exactly depends a lot on configuration, which can vary greatly from OS to OS (you can configure everything to your likings, however this exceeds the scope of this short introduction). Generally it will indicate yourcurrent working directory,username andhostname. When working in the shell your session always hascurrent working directory. Commands that accept relative filenames will use that directory as the base directory to look for files. By default you are in your user's home folder, which is often abbreviated with a tilde (~).

To execute a command you just type it into the shell and press enter.

At first we want to look at the commandls. If you type it in just like that it will print the files and directories in your current working directory. You can also provide a relative path to a directory you want to list, e.g.ls DIR. If you want more detailed information about the files you can usels -l DIR, if you instead want to also include invisible entries (i.e. names starting with a dot) usels -a. Of course it is possible to combine them both by runningls -l -a DIR or the short formls -la DIR. Note that this kind of concatenating multiple arguments into one is only possible with single character parameters. Parameters can also come in long form, for example the equivalent ofls -a isls --all DIR. Which forms are available depends on the individual command.

Now you might be thinking how to remember all parameters for every command you will ever use. Thankfully you only want to remember the most important ones, which are the ones you use most frequently, otherwise there is a nice way to look them up. You can either use theman command. For example runman ls to find more information about thels command. Oftentimes you can find a more concise summary by trying to run the command in question followed by the parameter--help, however this is not something you can expect to work well with every command, whereas manual pages should be always available.

Back to the topic of current working directories. If you want to change your directory you can usecd followed by the directory you want to change to. There are two special virtual directories '.' and '..'. The single dot refers to the current directory while the double dot refers to a dir's parent directory. So executingcd .. changes into the parent directory of the current working directory.

A very brief summary of other useful commands:

cat FILE: display the contents of a file.

mkdir DIR: create a directory.


System-wide installation

[edit |edit source]

A common and easy way to install Ruby is to perform a system-wide installation. Depending on the operating system installation procedures will be different (if required at all).

Windows logo - 2012

Windows

[edit |edit source]

Windows Operating Systemdid not have Ruby programing language pre-installed (unlike other platforms listed here) . To install Ruby programming language, it is highly recommended to install it from here:https://rubyinstaller.org/ .

Refer to right side bar:WHICH VERSION TO DOWNLOAD? for guide to download which version to download. Usually it will recommend thelatest stable version to be downloaded.

You might see the options ofRuby+Devkit installer version as a selectable component. This option is important as to build native C/C++ extensions for Ruby and is necessary forRuby on Rails. Moreover it allows the download and usage of hundreds of Open Source libraries which Ruby gems (packages) often depend on.

Download it and double click the file to be installed on the local PC.

Once install it, double click of Ruby Installer to start installing it on Windows

Step 1: Select "I accept the license" and click "Next" button

Step 2: Select the directory that you wanted to install to and below , select the "Add Ruby executables to your PATH" and "Associate .rb and .rbw files with the Ruby installation". Click "Next" buttons"

Step 3: Select all the checkboxes inside the setup files. Click "Next"

Step 4: Click "ridk install" and click "Next" button to proceed


Once finished installing, typecmd into Window search bar and typeruby -v sto see which version of ruby that are installed. If it is showing, congrats, you successfully installed Ruby language in the system.

MacOS logo (2017) macOS

[edit |edit source]

Ruby comes preinstalled on macOS. To check which version is installed on your system, executeruby -v inside a shell session.

If you want to install a more recent version of Ruby, you can:

  • Update to a newer version of macOS, which may have a more recent version of Ruby.
  • UseRVM orRBEnv tools specifically for managing multiple ruby versions (This is the most popular way because you can manage many Ruby versions and associate them with projects)
  • UseFink,MacPorts,Homebrew general purpose packaging systems for mac.

Monochrome Tux Linux

[edit |edit source]

On many Linux distributions Ruby is installed by default. To check if Ruby is installed on your system, runruby -v in a shell session.

Where this is not the case, or you want to update the installed version, you should use your distribution'spackage manager.Here we will provide information for some popular Linux distributions here, however it is recommended to users of all distributions to familiarize themselves with their distribution's package manager, since this will allow for the most efficient software management. Whether this is a command-line or graphical application depends on the offerings of the distribution and personal preference of the user.

Debian / Ubuntu

[edit |edit source]

The package managerSynaptic provides graphical package management. It is installed by default under Ubuntu and has to be installed manually on Debian (by runningsudo apt-get install synaptic from the command line).

Instead of using Synaptic you can also useapt directly from the command-line (you can find further information in the Debian Wiki's article onPackage Management). Executesudo apt-get install ruby from the command line to install Ruby.

Fedora

[edit |edit source]

From the command-line you can install Ruby withDNF by executingsudo dnf install ruby.

Arch Linux

[edit |edit source]

Usepacman to install Ruby by executingpacman -S ruby as root.

Mandriva Linux

[edit |edit source]

OnMandriva Linux, install Ruby using the command-line toolurpmi.

PCLinuxOS

[edit |edit source]

On PCLinuxOS, install Ruby using either the graphical tool Synaptic or the command-line tool apt.

Red Hat Linux

[edit |edit source]

OnRed Hat Linux, install Ruby using the command-line toolRPM.

Per-user Installation

[edit |edit source]

Per-user installations allow each user of the system to utilize their own particular version of Ruby without impact to other users.

Guix

[edit |edit source]

To install the latest available version of Ruby, run:guix install ruby.

Setup Ruby in Windows

[edit |edit source]

Ruby does not come preinstalled with any version ofMicrosoft Windows. However, there are several ways to install Ruby on Windows.

  • Download and install one of the compiled Ruby binaries from theRuby web site.
  • Download and run the one clickRubyInstaller.
  • InstallCygwin, a collection offree software tools available for Windows. During the install, make sure that you select the "ruby" package, located in the "Devel, Interpreters" category.

Setup Ruby in Windows with Notepad++

[edit |edit source]

In latest version of Ruby and Window 10 , it is much more easier to setup Ruby now more than ever.

We will be using[1]Notepad++ Logo to start setup Ruby in Windows.

Once install Notepad++ in Windows, open up the programs and click onPlugins >Plugins Admin

AtPlugins Admin , select Plugins ,NppExec to install

Once installed, you can runNppExec by pressingF6

Building from Source

[edit |edit source]

If your distro doesn't come with a ruby package or you want to build a specific version of ruby from scratch, please install it by following the directionshere. Download fromhere.

Compile options

[edit |edit source]

Building with debug symbols

[edit |edit source]

If you want to install it with debug symbols built in (and are using gcc--so either Linux, cygwin, or mingw).

 ./configure --enable-shared optflags="-O0" debugflags="-g3 -ggdb"

Optimizations

[edit |edit source]

Note that with 1.9 you can pass it --disable-install-doc to have it build faster.

To set the GC to not run as frequently (which tends to provide a faster experience for larger programs, like rdoc and rails), precede your build with

 $ export CCFLAGS=-DGC_MALLOC_LIMIT=80000000

though you might be able to alternately put those in as opt or debug flags, as well.

Testing Installation

[edit |edit source]

The installation can be tested easily by executing:

$ ruby -v

This should produce an output similar to:

ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]

If this shows up, then you have successfully installed Ruby. However if you get an error similar to:

-bash: ruby: command not found

then you did not successfully install Ruby.

Retrieved from "https://en.wikibooks.org/w/index.php?title=Ruby_Programming/Installing_Ruby&oldid=4222320"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp