How To Install ruby-nio4r on Ubuntu 18.04

In this tutorial we learn how to install ruby-nio4r on Ubuntu 18.04. ruby-nio4r is Ruby library providing a selector API for monitoring IO objects

Introduction

In this tutorial we learn how to install ruby-nio4r on Ubuntu 18.04.

What is ruby-nio4r

ruby-nio4r is:

nio4r (New IO for Ruby) provides an abstract, cross-platform stateful I/O selector API for Ruby. I/O selectors are the heart of “reactor”-based event loops, and monitor multiple I/O objects for various types of readiness, e.g. ready for reading or writing.

The most similar API provided by Ruby today is Kernel.select, however the select API requires you to pass in arrays of all of the I/O objects you’re interested in every time. nio4r provides a more object-oriented API that lets you register I/O objects with a selector then handle them when they’re selected for various types of events.

nio4r is modeled after the Java NIO API, but simplified for ease-of-use.

Its goals are:

  • Expose high-level interfaces for stateful IO selectors.
  • Keep the API small to maximize both portability and performance across many different OSes and Ruby VMs.
  • Provide inherently thread-safe facilities for working with IO objects.

There are three methods to install ruby-nio4r on Ubuntu 18.04. We can use apt-get, apt and aptitude. In the following sections we will describe each method. You can choose one of them.

Install ruby-nio4r Using apt-get

Update apt database with apt-get using the following command.

sudo apt-get update

After updating apt database, We can install ruby-nio4r using apt-get by running the following command:

sudo apt-get -y install ruby-nio4r

Install ruby-nio4r Using apt

Update apt database with apt using the following command.

sudo apt update

After updating apt database, We can install ruby-nio4r using apt by running the following command:

sudo apt -y install ruby-nio4r

Install ruby-nio4r Using aptitude

If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude using the following command.

sudo aptitude update

After updating apt database, We can install ruby-nio4r using aptitude by running the following command:

sudo aptitude -y install ruby-nio4r

How To Uninstall ruby-nio4r on Ubuntu 18.04

To uninstall only the ruby-nio4r package we can use the following command:

sudo apt-get remove ruby-nio4r

Uninstall ruby-nio4r And Its Dependencies

To uninstall ruby-nio4r and its dependencies that are no longer needed by Ubuntu 18.04, we can use the command below:

sudo apt-get -y autoremove ruby-nio4r

Remove ruby-nio4r Configurations and Data

To remove ruby-nio4r configuration and data from Ubuntu 18.04 we can use the following command:

sudo apt-get -y purge ruby-nio4r

Remove ruby-nio4r configuration, data, and all of its dependencies

We can use the following command to remove ruby-nio4r configurations, data and all of its dependencies, we can use the following command:

sudo apt-get -y autoremove --purge ruby-nio4r

References

Summary

In this tutorial we learn how to install ruby-nio4r package on Ubuntu 18.04 using different package management tools: apt, apt-get and aptitude.