How To Install Ruby with rbenv on Cent OS 7.2

[root@contoso ~]# yum install -y openssl-devel readline-devel zlib-devel


Now we are ready to install rbenv. Let's clone the rbenv repository from git. You should complete these steps from the user account from which you plan to run Ruby.


[root@contoso ~]# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
From here, you should add ~/.rbenv/bin to your $PATH so that you can use rbenv's command line utility. Also adding ~/.rbenv/bin/rbenv init to your ~/.bash_profile will let you load rbenv automatically.


[root@contoso ~]# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
[root@contoso ~]# echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Next, source rbenv by typing:


[root@contoso ~]# source ~/.bashrc
You can check to see if rbenv was set up properly by using the type command, which will display more information about rbenv:


[root@contoso ~]# type rbenv
Your terminal window should output the following:


Output
rbenv is a function
rbenv () 

    local command;
    command="$1";
    if [ "$#" -gt 0 ]; then
        shift;
    fi;
    case "$command" in 
        rehash | shell)
            eval "$(rbenv "sh-$command" "$@")"
        ;;
        *)
            command rbenv "$command" "$@"
        ;;
    esac
}
In order to use the rbenv install command, which simplifies the installation process for new versions of Ruby, you should install ruby-build, which we will install as a plugin for rbenv through git:


[root@contoso ~]# git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
At this point, you should have both rbenv and ruby-build installed, and we can move on to installing Ruby.


Install Ruby
With the ruby-build rbenv plugin now installed, we can install whatever versions of Ruby that we may need through a simple command. First, let's list all the available versions of Ruby:


[root@contoso ~]# rbenv install -l
The output of that command should be a long list of versions that you can choose to install.


We'll now install a particular version of Ruby. It's important to keep in mind that installing Ruby can be a lengthy process, so be prepared for the installation to take some time to complete.


As an example here, let's install Ruby version 2.3.1, and once it's done installing, we can set it as our default version with the global sub-command:


[root@contoso ~]# rbenv install 2.4.1
[root@contoso ~]# rbenv global 2.4.1
If you would like to install and use a different version, simply run the rbenv commands with a different version number, as in rbenv install 2.3.0 and rbenv global 2.3.0.


Verify that Ruby was properly installed by checking your version number:




[root@contoso ~]# rbenv global 2.4.1


 
If you installed version 2.4.1 of Ruby, your output to the above command should look something like this:


Output
[root@contoso ~]# ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
You now have at least one version of Ruby installed and have set your default Ruby version. Next, we will set up gems and Rails.


Working with Gems
Gems are packages that extend the functionality of Ruby. We will want to install Rails through the gem command.


So that the process of installing Rails is less lengthy, we will turn off local documentation for each gem we install. We will also install the bundler gem to manage application dependencies:


[root@contoso ~]# echo "gem: --no-document" > ~/.gemrc
[root@contoso ~]# gem install bundler
Fetching: bundler-1.15.4.gem (100%)
Successfully installed bundler-1.15.4
1 gem installed
You can use the gem env command (the subcommand env is short for environment) to learn more about the environment and configuration of gems. You can check the location where gems are being installed by using the home argument, which will show the pathway to where gems are installed on your server.


[root@contoso ~]# gem env home
Your output should look something like this, with root being the name of the user:


[root@contoso ~]# gem env home
/root/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0




Uninstalling Ruby versions


[root@contoso ~]# rbenv uninstall 2.4.1
1、资源项目源码均已通过严格测试验证,保证能够正常运行;、 2项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行;、 2项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 、 1资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READmE.文件(md如有),本项目仅用作交流学习参考,请切勿用于商业用途。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值