thumb

Every time we perform an update with gem update the default behaviour is to install a new version of a gem and continue maintaining the older version of that gem. Most likely, if you have been using Ruby for a while, your system will be full of gems, and more specifically, outdated gems. So how do we uninstall a Ruby gems that are no longer needed? In this tutorial, you’ll learn how to uninstall a Ruby gems.

Let’s begin

Uninstalling Ruby gems is a really easy process. To do this, we will use the gem uninstall and gem cleanup commands of the Gem package manager. Now, step by step guide.

Removing a specific gem

Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.

Type the following command to uninstall the gem GEMNAME (replace the “GEMNAME” with the name of a gem you want to uninstall):

sudo gem uninstall GEMNAME

Or type the following command instead to uninstall only the version 1.1.0 of the gem GEMNAME:

sudo gem uninstall GEMNAME --version 1.1.0

This commands will prompt us to enter our computer password. Enter your password and answer any prompts given by the command. Depending on the configuration of the gem itself, you may be asked to specify the versions to uninstall or asked to confirm the uninstallation.

Note! It’s normal that the password you enter is not displayed. This is how the password is entered on the command line. Just enter your password, and then press the Enter key.

Successfully uninstalled gemname-1.1.0

Note! If you uninstall a dependency of a gem RubyGems will ask you for confirmation.

Removing old versions of a specific gem

Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.

Type the following command to uninstall all old versions of the gem GEMNAME (replace the “GEMNAME” with the name of a gem you want to uninstall):

sudo gem cleanup GEMNAME

This command will prompt us to enter our computer password. Enter your password and then watch the magic happen…

Note! It’s normal that the password you enter is not displayed. This is how the password is entered on the command line. Just enter your password, and then press the Enter key.

Successfully uninstalled gemname-0.1.0

Note! If you uninstall a dependency of a gem RubyGems will ask you for confirmation.

Removing old versions of all gems

Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.

Type the following command to uninstall old versions of all installed gems:

sudo gem cleanup

This command will prompt us to enter our computer password. Enter your password and then watch the magic happen…

Note! It’s normal that the password you enter is not displayed. This is how the password is entered on the command line. Just enter your password, and then press the Enter key.

Password:
Cleaning up installed gems...
Attempting to uninstall rubyzip-1.2.2
Successfully uninstalled rubyzip-1.2.2
Attempting to uninstall progressbar-1.10.0
Successfully uninstalled progressbar-1.10.0
Attempting to uninstall rubyzip-1.3.0
Successfully uninstalled rubyzip-1.3.0
Attempting to uninstall gemoji-3.0.0
Successfully uninstalled gemoji-3.0.0
Clean up complete

Conclusion

That’s it, you’re done. Now you have uninstalled a Ruby gems that are no longer needed. So simple isn’t it?

I hope this article has helped you learn how to uninstall a Ruby gems. If this article helped you then please leave a comment :smiley:

Thanks for reading!