Home > database >  bundler using system ruby version instead of downloaded
bundler using system ruby version instead of downloaded

Time:12-22

This is a basic question, but I've been banging my head against a wall trying to fix this and I'm stuck.

I'm cloning a rails project.

When I run bundle install I get:

Your Ruby version is 2.6.8, but your Gemfile specified 2.5.5

so I tried to make sure that I'm using the right version using rbenv versions. I get:

  system
* 2.5.5 (set by /Users/Mahmoud/dev-reps/non-docker/backend/.ruby-version)

which means that rbenv is using the correct version. Now I run which bundle:

/usr/local/bin/bundle

which means that bundler is using the system version.

As for which -a bundle gives:

/usr/local/bin/bundle
/usr/bin/bundle

Also when I run which ruby or which -a ruby, I get:

/usr/bin/ruby

Something I tried though, points to light at the end of the tunnel. When [I try based on this post] this1:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

and rerun bundle install, it works. The problem though, the change isn't persistent. I close shell and retry, and I'm right where I started

I've uninstalled and re-installed bundler multiple times after rehashing, etc. but I'm still seeing that rbenv isn't "in control". It tells me one version is in use, but the fact is that the system version is being used.

Update

Based on one of the comments, I uninstalled rbenv and redownloaded. Now after rbenv rehash I get the following when I type which ruby:

/Users/Mahmoud/.rbenv/shims/ruby

which is perfect. which bundle however gives:

/usr/local/bin/bundle

so the problem persists. I also tried gem install bundler but still when I type bundle install I'm getting the same problem.

What am I doing wrong?

CodePudding user response:

It looks like you don't have rbenv set up in your shell. You can find the instructions on how to do this in the rbenv docs here.

CodePudding user response:

Okkk, so after hours and with help from comments here and the answer given above I was able to get it to work.

The problem it seemed was that rbenv was not properly setup. To fix it, it's either to uninstall and install again. Did this through:

  1. brew remove rbenv
  2. rm -rf ~/.rbenv
  3. Removed a line containing rbenv from ~/.zshrc

This removed rbenv. I then reinstalled using:

  1. brew install rbenv
  2. Then initialized using rbenv init. This effectively fixes the problem of rbenv. Now after restarting terminal, whenever I ran which ruby, I'd get:

/Users/Mahmoud/.rbenv/shims/ruby

meaning in short that the system now relies on rbenv for its ruby version management instead of looking in the system. This is crucial for the working of rbenv, and in essence this is it's whole "raison d'etre"; to take the job of managing ruby on your pc away from your pc.

After this step I ran gem install bundler. Following this step when I run which bundle it would give:

/Users/Mahmoud/.rbenv/shims/bundle

so everything is in place and working fine

  • Related