Skip to content

Latest commit

 

History

History
203 lines (111 loc) · 16.8 KB

README.md

File metadata and controls

203 lines (111 loc) · 16.8 KB

Why not?

You're probably here because you asked someone for help with the version of Ruby that came pre-installed with your operating system. Your question was probably related to installing, uninstalling, downgrading, upgrading, configuring, or using that version of Ruby.

You were sent here so the person you asked doesn't have to take the time to answer your question, because the answer is:

Don't use system Ruby. Use a Ruby version manager to compile and install Ruby yourself because system Ruby is not meant to be used directly.

Why should I trust you?

I've been developing Ruby apps professionally since 2013, both as an individual contributor and as an organizational leader, at both some of the largest Ruby shops in the world (like Yammer and New Relic) and at small startups. I've built multiple greenfield products from scratch using Ruby (and sometimes Ruby on Rails) and have also developed new engineer onboarding guides multiple times. I'm also active on Stack Overflow's ruby tag where questions are commonly solved by using a Ruby manager.

But if you don't trust me you can always rely on the wisdom of others:

What is Ruby?

When programmers talk about Ruby they're really talking about two different things: the programming language used to create Ruby apps and the interpreter used to run Ruby apps.

The Ruby language

The Ruby programming language is just like any other. Although there are important differences in how they work and are used, Ruby is comparable to Python, JavaScript, PHP, C, Swift, Rust, Go ... you name it!

The Ruby language was created in 1993 by Yukihiro Matsumoto ("Matz") and the first version was released in 1996. It's an open-source, dynamic, object-oriented and interpreted language, widely regarded for its simplicity and elegance.

The Ruby interpreter

The Ruby interpreter is a piece of software that reads and executes apps written in the Ruby language. Generally when speaking about the Ruby interpreter we're talking about MRI, also known as Matz's Runtime Implementation. This is the version of Ruby developed by the Ruby maintainers, and accordingly is the first interpreter to support new features of the language.

There are other Ruby interpreters like JRuby and TruffleRuby but these are less popular and considered niche in the Ruby community. If someone is talking about MRI then they'll typically say Ruby and if someone is talking about another interpreter then they'll call it by its proper name, like JRuby.

Unless you know that you specifically need an alternative Ruby interpreter it is recommended that you stick with MRI as it has the widest base of users.

What is system Ruby?

Any version of Ruby that comes pre-installed with the operating system or is available as a package through the operating system's package manager is system Ruby.

Ruby is freely available for anyone to use or modify, and it's possible to download its source code, compile it, and have it up and running on your computer in just a few minutes.

Since Ruby is available for free for commercial use, and since it is the version preferred by the core Ruby maintainers, and since it is the version the Ruby maintainers use to publish new features, Ruby is often bundled with operating systems like Linux and macOS. (some distributions of Linux may not include Ruby by default, but almost all will offer a package to install it)

Any version of Ruby that either came pre-installed with the operating system or can be downloaded using the operating system's package manager (like sudo apt install ruby) is what we call system Ruby.

What is non-system Ruby?

Any version of Ruby that you download and compile yourself (either with a tool or by hand) qualifies as non-system Ruby. The easiest way to know the difference is if you download a package to install Ruby then you have system Ruby. (because the package manager knows your operating system version and your architecture and thus knows the pre-compiled Ruby package will run safely)

Why not use system Ruby?

There are myriad reasons not to use system Ruby, and they all boil down to this simple reason:

!> System Ruby belongs to the operating system and is not under your control.

System Ruby is meant to be used by the OS and its packages

When your operating system ships with Ruby, or when you install Ruby from your package manager, you are getting a version of Ruby that has been made to work within the narrow confines of what the operating system needs. That means Ruby will be installed in the directory it wants, with the configuration it wants, for the use-cases of either the operating system or packages that might depend on it.

Even though it's conveniently present it isn't there for you to use. It's there for the operating system and its packages only. The operating system doesn't care that you're using it and may make changes to it at any time.

The Ruby package isn't like a package for a calendar or mail app, which are meant to be used by you. The Ruby package is meant to be used by the operating system and other packages, and if it stops working properly then the operating system can and will happily stomp out any changes you've made to restore the system to a functioning state.

!> System Ruby belongs to the operating system and is meant for use by the operating system and other packages, not by you.

System Ruby has restricted permissions

The filesystem on UNIX systems is protected by permissions. Certain directories and files have permissions that regular users on the system cannot change. Since the operating system wants to protect the tools that it relies on (like Ruby), the directories where Ruby is installed and where Ruby gems are installed have permissions that prevent users from making changes.

Of course, it's always possible to override this with sudo but when your operating system is telling you don't touch these files it's a good idea to pay attention.

!> System Ruby belongs to the operating system and may have filesystem permissions in place to prevent it from being used easily.

System Ruby is old

Most typically, the version of Ruby that ships with the system will be the version that was released when your operating system was released. Still running Ubuntu 18.04 LTS? Then your system Ruby version is 2.5.1, released in 2018.

Newer versions of Ruby will include bug fixes, security fixes, new features, and better performance. Additionally, new Ruby libraries may require newer versions of Ruby as they need new features of the language.

!> System Ruby belongs to the operating system and will be locked at whatever version it needs, no matter how old, insecure, and unstable it may be.

System Ruby can't be upgraded

Did your operating system ship with Ruby 2.7 but you want to take advantage of the new features of Ruby 3.0? Bad news, your operating system's maintainers haven't yet released (and maybe never will release) Ruby 3.0 as an update.

!> System Ruby belongs to the operating system and its maintainers may not make newer versions available.

System Ruby can't be downgraded

Good news, your favorite operating system has released a new version! Bad news, it shipped with Ruby 3.0, there are no packages for Ruby 2.7, and all your apps and Ruby gems require Ruby 2.7!

!> System Ruby belongs to the operating system and its maintainers may not make older versions available.

System Ruby can't be removed

If your operating system shipped with Ruby then chances are you can't remove it from your system. (an example of this is macOS) If you've modified (or damaged) your Ruby installation (and possibly left your operating system in an unstable state) then there may be no way to remove and reinstall Ruby — you have to reinstall the entire operating system.

!> System Ruby belongs to the operating system and can't always be removed or repaired.

System Ruby can't coexist with other versions of Ruby

Your operating system will only allow you to have one version of Ruby installed: the version it chooses for you. If you need a different version than the one installed, say 1.9.3 instead of 2.7, you're out of luck.

!> System Ruby belongs to the operating system and can't coexist with other versions.

System Ruby can change at any time

Even if you are able to use system Ruby successfully, there's no guarantee from the operating system that it won't modify, reset, or upgrade the version of Ruby present on the system. For example, when security updates for Ruby are released an updated version of system Ruby may be installed. The operating system has no way of knowing that you're using or have configured system Ruby and will happily overwrite the existing installation which can cause your Ruby apps to stop functioning.

!> System Ruby belongs to the operating system and can change at any time.

Why have system Ruby at all?

When apps get deployed the servers they run on should be as simple and hardy as possible. Docker containers, for example, are typically stripped down to the smallest size. In this type of environment it may be beneficial to use a prebuilt version of Ruby, either one that comes with the operating system or one installed through a package, because it may be undesirable to compile Ruby from scratch every time a new instance of the app is deployed.

These environments are more rigidly constructed and less prone to change than a device used for development.

Version managers are great tools for development environments but not so much for production environments. If you're using a version manager in a production environment then you're probably doing something wrong.

How do I install Ruby?

Ruby is easy to install using a version manager. A version manager is an application that will manage the installation and removal of Ruby versions on your device.

There are many benefits to using a version manager:

  • Ruby will be downloaded fresh and compiled from scratch, ensuring it works best on your device
  • Ruby will be installed to the directory of your choosing, typically somewhere in your home directory, making it both portable and entirely under your control
  • Multiple versions of Ruby can be installed and used concurrently, from very old versions to the latest versions (including MRI, JRuby, TruffleRuby, and more)
  • The operating system and its packages won't know about any Ruby installation done with a version manager, and thus can't interfere with it
  • Each version of Ruby might require different steps to compile it from scratch but version managers maintain configurations for each version so they will always know how to install any given version — no fiddling with a Makefile required

What version managers are there?

The version managers listed here are the most commonly used. There are other ways to install Ruby but for the vast majority of people the managers here are the primary ways to do it. You can always check the Ruby installation instructions for an up-to-date list of possible version managers.

asdf-vm

asdf-vm is a version manager built to support multiple tools, including Ruby, Java, node, Python, Go, and many others.

  • This might be a good solution for you if you need to manage more than just Ruby.
  • This might not be a good solution for you if you aren't familiar with the shell environment; it has a steeper learning curve than others and may require some hard-to-find documentation to get working. (but once you do, the knowledge will allow you to install and manage other tools easily)
  • It has a large community for support.

RVM

RVM is a version manager built specifically and only for Ruby. It's been around a long time and has a broad community of support.

  • This might be a good solution for you if you only need to manage Ruby.
  • This might not be a good solution for you if you have multiple other tools installed or a highly configured shell environment.

chruby

chruby is a lot like rbenv but much lighter weight, and is built specifically and only for Ruby.

  • This might be a good solution for you if you only need to manage Ruby, or if you don't need the configuration options provided by other version managers.
  • This might not be a good solution for you if you aren't familiar with your shell environment and want the simplest, smallest manager available.

rbenv

rbenv is a lot like asdf-vm and works mostly in the same ways, but is built specifically and only for Ruby.

  • This might be a good solution for you if you only need to manage Ruby, or if you're familiar with similar tools like pyenv.
  • This might not be a good solution for you if you have multiple other tools installed or a highly configured shell environment.

What is the best version manager?

The version manager you choose will depend on your needs and your comfort level with the shell environment. Here are some things to consider:

  • Do you need to manage more than just Ruby? (e.g. Java, node, Python, Go, etc.)
  • Do you already use similar tools? (pyenv, nodeenv, etc.)
  • Are you very comfortable using the shell environment? (e.g., you know what PATH is and how to modify it, you know what ~/.bash_profile is and how to edit it, etc.)

Each manager has its own strengths and weaknesses. There is no best manager, only the one that works best for you. That said, if you do not have any version manager installed (you are starting from scratch or are a completely new user) then I would recommend using asdf-vm as it is the most flexible and powerful. It can accommodate many languages and tools, not just Ruby, and has a large community of support. It uses the fundamentals of tools like pyenv, rbenv and nodeenv but is more flexible than any of them and can be used as a single tool to replace those multiple tools.

How do I use a version manager?

The steps to install and use a version manager vary between tools and over time. Refer to the website of each manager for up-to-date instructions for installing a version manager and Ruby. Keep in mind that the version manager will download, compile, and install Ruby, but it's up to you to tell it what version you want installed (and what version you want to use in any given shell session), so make sure you carefully read the documentation for the version manager you select.

The general process for using a version manager is:

  1. Download and install the manager.
  2. Download and install Ruby using the manager.
  3. Ensure your shell has been configured properly to use the new version of Ruby you just installed.
  4. Run which ruby and ruby -v to ensure the correct version and copy of Ruby is being used.

How do I get help?

Head over to Stack Overflow and ask a question. There are many good people who will be happy to provide support.

Please take time to read the following articles from the StackOverflow Help Center before posting a question to ensure you get the best possible help:

How do I update these docs?

This documentation is open source and available on GitHub. Open a pull request with any recommended changes.


Copyright © 2023, dontusesystemruby.com