ruby安装设置笔记
文章目录
- ruby安装设置笔记
- 1 克隆并设置环境变量
- 2 安装ruby
- 3 设置ruby
- 4 设置源
- 5 安装bundler
- 6 检查安装后的软件版本
- 7 ubuntu 20.04 默认ruby环境
系统自带的ruby版本低了,需要手动安装更高版本(使用rbenv方式)
环境:Ubuntu 20.04 桌面环境
1 克隆并设置环境变量
- 我的
~/.bashrc
添加以下内容
# - rbenv
# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# - ruby-build
# 用来编译安装ruby的程序
# git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
# - ruby gems 路径
# 可以通过运行`gem environment`查看安装路径
# 默认:系统级安装目录为:/var/lib/gems
# 用户级安装目录为:$HOME/.gem
# 指定安装 Ruby Gems 到目录:~/.gem_4_me
export GEM_HOME="$HOME/.gem_4_me"
export PATH="$HOME/.gem_4_me/bin:$PATH"
- 使其原地生效:
exec $SHELL
2 安装ruby
rbenv install -l #-- 列出可安装ruby版本
rbenv install 3.2.2
3 设置ruby
rbenv global 3.2.2 #-- 设置默认ruby版本
rbenv rehash #-- 重新生成ruby可执行shims
4 设置源
国内的快
gem sources -l #-- 列出添加的源
gem sources --remove https://rubygems.org/ #-- 移除官方源
gem sources -a https://gems.ruby-china.com/ #-- 添加ruby-china源
gem sources -a https://mirrors.aliyun.com/rubygems/ #-- 添加国内阿里云源
5 安装bundler
Bundler 可管理 Ruby gem 依赖项,写在
Gemfile
文件中的依赖gem,可以运行bundle install
自动安装
gem install bundler
6 检查安装后的软件版本
rbenv -v
ruby -v
gem -v
bundler -v
7 ubuntu 20.04 默认ruby环境
kevin@TM1701-b38cbc23:~$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 3.1.2
- RUBY VERSION: 2.7.0 (2019-12-25 patchlevel 0) [x86_64-linux-gnu]
- INSTALLATION DIRECTORY: /var/lib/gems/2.7.0
- USER INSTALLATION DIRECTORY: /home/kevin/.gem/ruby/2.7.0
- RUBY EXECUTABLE: /usr/bin/ruby2.7
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /home/kevin/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/2.7.0
- /home/kevin/.gem/ruby/2.7.0
- /usr/lib/ruby/gems/2.7.0
- /usr/share/rubygems-integration/2.7.0
- /usr/share/rubygems-integration/all
- /usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/kevin/.local/bin
- /usr/local/pgsql/bin
- /opt/node/bin
- /opt/maven/bin
- /opt/java/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /snap/bin
gem安装路径:
- INSTALLATION DIRECTORY
- USER INSTALLATION DIRECTORY
- GEM PATHS