Search code examples
rubyubunturbenv

How configure bash environment with rbenv?


I'm actually working to maintain a Ruby application on a server which is not up to date (Ubuntu 10.04.2 LTS). RVM is installed globaly, i've tried to obtain a recent ruby version locally, in my home directory, without any success. And now I'm trying with rbenv.

I've just installed Ruby 2.3.1 with rbenv & ruby-build (as rbenv plugins). The install worked perfectly, but not the usage.

The installation (the easy part) :

$ rbenv install 2.3.1
Downloading ruby-2.3.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2
Installing ruby-2.3.1...
Installed ruby-2.3.1 to /home/atlantic/.rbenv/versions/2.3.1

I've updated the .bash_profile like they said :

$ cat .bash_profile 
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

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

But when I want to check the environnement lot of environnement parameters use global path (like GEM PATHS, EXECUTABLE DIRECTORY, INSTALLATION DIRECTORY, ...) :

$ gem env 
RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-2.0.0-p247
  - USER INSTALLATION DIRECTORY: /home/atlantic/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /home/atlantic/.rbenv/versions/2.3.1/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-2.0.0-p247/bin
  - SPEC CACHE DIRECTORY: /home/atlantic/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/rvm/gems/ruby-2.0.0-p247
     - /usr/local/rvm/gems/ruby-2.0.0-p247@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/atlantic/.rbenv/versions/2.3.1/bin
     - /home/atlantic/.rbenv/libexec
     - /home/atlantic/.rbenv/plugins/ruby-build/bin
     - /home/atlantic/.rbenv/shims
     - /home/atlantic/.rbenv/bin
     - /usr/local/rvm/gems/ruby-2.0.0-p247/bin
     - /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin
     - /usr/local/rvm/rubies/ruby-2.0.0-p247/bin
     - /usr/local/rvm/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games

When I look the env, there lot of env variables who target the global ruby installation. I do not know from where theses variables we're set but that's not the value I want for them :

$ env |grep -i ruby
GEM_HOME=/usr/local/rvm/gems/ruby-2.0.0-p247
IRBRC=/usr/local/rvm/rubies/ruby-2.0.0-p247/.irbrc
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.0.0-p247
PATH=/home/atlantic/.rbenv/shims:/home/atlantic/.rbenv/bin:/usr/local/rvm/gems/ruby-2.0.0-p247/bin:/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p247/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
GEM_PATH=/usr/local/rvm/gems/ruby-2.0.0-p247:/usr/local/rvm/gems/ruby-2.0.0-p247@global
RUBY_VERSION=ruby-2.0.0-p247

The rbenv ruby installation never appear on theses variables. Do I have a command (like a rbenv init-env-variables) to lauch to configure correctly my ruby env ?

Thanks for your support, David


Solution

  • I've manually update the file .bash_profile to unset all variables environnements which in use with rvm and now it works perfectly :

    $ cat /home/atlantic/.bash_profile 
    # include .bashrc if it exists
    if [ -f ~/.bashrc ]; then
        . ~/.bashrc
    fi
    
    unset rvm_bin_path
    unset GEM_HOME
    unset IRBRC
    unset MY_RUBY_HOME
    unset rvm_path
    unset rvm_prefix
    unset rvm_version
    unset GEM_PATH
    unset RUBY_VERSION
    
    
    export PATH="$HOME/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"
    

    The result :

    $ gem env
    RubyGems Environment:
      - RUBYGEMS VERSION: 2.5.1
      - RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-linux]
      - INSTALLATION DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
      - USER INSTALLATION DIRECTORY: /home/atlantic/.gem/ruby/2.3.0
      - RUBY EXECUTABLE: /home/atlantic/.rbenv/versions/2.3.1/bin/ruby
      - EXECUTABLE DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/bin
      - SPEC CACHE DIRECTORY: /home/atlantic/.gem/specs
      - SYSTEM CONFIGURATION DIRECTORY: /home/atlantic/.rbenv/versions/2.3.1/etc
      - RUBYGEMS PLATFORMS:
        - ruby
        - x86_64-linux
      - GEM PATHS:
         - /home/atlantic/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
         - /home/atlantic/.gem/ruby/2.3.0
      - GEM CONFIGURATION:
         - :update_sources => true
         - :verbose => true
         - :backtrace => false
         - :bulk_threshold => 1000
      - REMOTE SOURCES:
         - https://rubygems.org/
      - SHELL PATH:
         - /home/atlantic/.rbenv/versions/2.3.1/bin
         - /home/atlantic/.rbenv/libexec
         - /home/atlantic/.rbenv/plugins/ruby-build/bin
         - /home/atlantic/.rbenv/shims
         - /home/atlantic/.rbenv/bin
         - /usr/local/rvm/gems/ruby-2.0.0-p247/bin
         - /usr/local/rvm/gems/ruby-2.0.0-p247@global/bin
         - /usr/local/rvm/rubies/ruby-2.0.0-p247/bin
         - /usr/local/rvm/bin
         - /usr/local/sbin
         - /usr/local/bin
         - /usr/sbin
         - /usr/bin
         - /sbin
         - /bin
         - /usr/games
    

    Thanks for your suggestions and your help. David.