How do I add directories to PATH?

£可爱£侵袭症+ 提交于 2019-12-08 05:20:39

问题


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"

回答1:


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.




回答2:


According to the documentation you should install the ruby-build plugin:

The rbenv install command doesn't ship with rbenv out of the box, but is provided by the ruby-build project.



来源:https://stackoverflow.com/questions/46188012/how-do-i-add-directories-to-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!