DEV Community

Cover image for How to set-up Ruby & Gems paths - Ruby snap package version
Ali Al Khawaja
Ali Al Khawaja

Posted on

How to set-up Ruby & Gems paths - Ruby snap package version

Hi

This post is for the developers that want to use ruby the snap version .

Lets start

Step 1.0: Delete the old Install

If you have tried to install Ruby the snap packaged version and faced problems using gems in VSCode or what ever then you need to remove them

Do this to remove Ruby ->

snap remove ruby
Enter fullscreen mode Exit fullscreen mode

or

just remove Ruby using the snap store (app center) , then go and delete the .gem folder , you'll find the .gem folder in the home folder and it's hidden by default

you should have ruby uninstalled and deleted .gems folder

Step 1.1 : Installing Ruby 🙂

Install ruby
There is two ways to install it

  1. using snap store (app center)
  2. using the terminal
sudo snap intall ruby --classic
Enter fullscreen mode Exit fullscreen mode

The --classic flag is used because Ruby requires classic confinement to access certain system resources.

Step 2: Verify the Installation

After the installation is complete, you can verify that Ruby is installed correctly by checking its version:

ruby --version
Enter fullscreen mode Exit fullscreen mode

Step 3: Set Up the PATH

You need to add the Snap binary directory to your PATH. I don't what is this but you can do it by editing your .bashrc file.

  1. Open your .bashrc in a text editor
gnome-text-editor ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  1. Add the following line at the end of the txt file:
export PATH="$PATH:/snap/bin"
export PATH="$PATH:/path/to/gem/bin"
Enter fullscreen mode Exit fullscreen mode

Replace /path/to/gem/bin with your path .
It should look like something like this :

export PATH="$PATH:/home/ali/.gem/bin"
Enter fullscreen mode Exit fullscreen mode

or this :

export PATH="$PATH:/home/your_username/.gem/ruby/3.x.x/bin"
Enter fullscreen mode Exit fullscreen mode

To make sure what is your path , check the gem path using this command in the terminal:

gem env
Enter fullscreen mode Exit fullscreen mode

It will list a long list of things about RubyGems Environment , we need the - EXECUTABLE DIRECTORY: path line .

Now save your changes and reload your shell config using :

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Now when you download any new gem , it will work automatically , try installing Rspec and test it in both VSCode and Terminal

The reason why I told you to delete the old .gem folder is becasue no one wants to manually edit the shebang line , I don't know what is a shebang but that's what ChatGPT told me .

That's it

See you later

Top comments (1)

Collapse
 
ali-alkhawaja profile image
Ali Al Khawaja

Good luck trying to install Ruby-LSP

I can't fix it , it's not working because snap packages 🙄 and I can't find any guide on this subject , not even the docs

I will install Ruby using rbenv now , Good luck guys , I really wanted Ruby snap version this to work .