Search code examples
bashpathrbenvwebfaction

How do I add directories to PATH?


Long story made short, I am trying to issue myself an SSL certificate using LetsEncrypt, and have recently installed rbenv to make this process easier. After installing rbenv, I check to see if everything checks out using

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

I than get this message saying that there are no versions of ruby installed. After trying to install ruby using the command

"rbenv install 2.3.1"

I get this error

rbenv: no such command `install'

Is it because the path to my rbenv shims aren't in my PATH variable ? If this is the case how do I add directories to my PATH variable ? I know you have to add them to your bash_profile file, but am not sure where in this file I need to add something, and what I need to add.

~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

function letsencrypt_webfaction {
    PATH=$PATH:$GEM_HOME/bin GEM_HOME=$HOME/.letsencrypt_webfaction/gems RUBYLIB=$GEM_HOME/lib ruby2.2 $HOME/.letsencrypt_webfaction/gems/bin/letsencrypt_webfaction $*
}

eval "$(rbenv init -)"


PATH=$PATH:$HOME/bin

export PATH
export PATH="$HOME/.rbenv/bin:$PATH"

Solution

  • Always be careful when editing the profile.

    Better make a backup first

    • switch to home directory: cd
    • list hiden files: ls -la .bash*
    • make a backup copy of .bash_profile: cp -p .bash_profile .bash_profile.bak
    • check the current PATH: echo $PATH
    • check if ruby is in the PATH: which ruby
    • check the ruby version: ruby --version

    I am not sure where this function is comming from in your .bash_profile: function letsencrypt_webfaction()

    Use : as a separator and add a new directory new_dir to your PATH, use $PATH to keep the contents of the actual PATH, then export the new PATH:

    PATH=$PATH:/new_dir:/new_lib
    export PATH
    

    Verify if the PATH is what you need from the terminal: echo $PATH

    Personaly I sugest making a backup of .bash_profile as it is. Comment out with # the 3 lines for the function and the others where the PATH appears and add this:

    export RUBYLIB=$HOME/lib
    export GEM_HOME=$HOME/gems
    export PATH=$HOME/bin:$PATH:
    

    After this please check the bulet points above and see if you have the ruby version you expect.