• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

使用Rbenv安装Ruby

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

使用Rbenv安装Ruby

需要安装的工具

sudo yum install git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-deve

直接执行安装即可

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

如果上面的地址无法访问,则可以使用下面的脚本,将其保存为rbenv-installer后,bash rbenv-installer即可。2020年5月27日15:44:21

#!/bin/bash
set -e

homebrew=
type -p brew >/dev/null && homebrew=1

try_bash_extension() {
  if [ -x src/configure ]; then
    src/configure && make -C src || {
      echo "Optional bash extension failed to build, but things will still work normally."
    }
  fi
}

if ! type -p git >/dev/null; then
  git() {
    echo "Error: git is required to proceed. Please install git and try again." >&2
    exit 1
  }
fi

http() {
  local url="$1"
  if type -p curl >/dev/null; then
    curl -fsSL "$url"
  elif type -p wget >/dev/null; then
    wget -q "$url" -O-
  else
    echo "Error: couldn't download file. No \`curl' or \`wget' found." >&2
    return 1
  fi
}

rbenv="$(command -v rbenv ~/.rbenv/bin/rbenv | head -1)"

if [ -n "$rbenv" ]; then
  echo "rbenv already seems installed in \`$rbenv'."
  cd "${rbenv%/*}"

  if [ -x ./brew ]; then
    echo "Trying to update with Homebrew..."
    brew update >/dev/null
    if [ "$(./rbenv --version)" < "1.0.0" ] && brew list rbenv | grep -q rbenv/HEAD; then
      brew uninstall rbenv
      brew install rbenv --without-ruby-build
    else
      brew upgrade rbenv
    fi
  elif git remote -v 2>/dev/null | grep -q rbenv; then
    echo "Trying to update with git..."
    git pull --tags origin master
    cd ..
    try_bash_extension
  fi
else
  if [ -n "$homebrew" ]; then
    echo "Installing rbenv with Homebrew..."
    brew update
    brew install rbenv --without-ruby-build
    rbenv="$(brew --prefix)/bin/rbenv"
  else
    echo "Installing rbenv with git..."
    mkdir -p ~/.rbenv
    cd ~/.rbenv
    git init
    git remote add -f -t master origin https://github.com/rbenv/rbenv.git
    git checkout -b master origin/master
    try_bash_extension
    rbenv=~/.rbenv/bin/rbenv

    if [ ! -e versions ] && [ -w /opt/rubies ]; then
      ln -s /opt/rubies versions
    fi
  fi
fi

rbenv_root="$("$rbenv" root)"
ruby_build="$(command -v "$rbenv_root"/plugins/*/bin/rbenv-install rbenv-install | head -1)"

echo
if [ -n "$ruby_build" ]; then
  echo "\`rbenv install' command already available in \`$ruby_build'."
  cd "${ruby_build%/*}"

  if [ -x ./brew ]; then
    echo "Trying to update with Homebrew..."
    brew update >/dev/null
    brew upgrade ruby-build
  elif git remote -v 2>/dev/null | grep -q ruby-build; then
    echo "Trying to update with git..."
    git pull origin master
  fi
else
  if [ -n "$homebrew" ]; then
    echo "Installing ruby-build with Homebrew..."
    brew update
    brew install ruby-build
  else
    echo "Installing ruby-build with git..."
    mkdir -p "${rbenv_root}/plugins"
    git clone https://github.com/rbenv/ruby-build.git "${rbenv_root}/plugins/ruby-build"
  fi
fi

# Enable caching of rbenv-install downloads
mkdir -p "${rbenv_root}/cache"

echo
echo "Running doctor script to verify installation..."
http https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | "$BASH"

echo
echo "All done!"
echo "Note that this installer doesn't yet configure your shell startup files:"
i=0
if [ -x ~/.rbenv/bin ]; then
  echo "$((++i)). You'll want to ensure that \`~/.rbenv/bin' is added to PATH."
fi
echo "$((++i)). Run \`rbenv init' to see instructions how to configure rbenv for your shell."
echo "$((++i)). Launch a new terminal window to verify that the configuration is correct."
echo

设置环境变量

# .bashrc

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

安装Ruby版本

rbenv install 2.5.8

使用Ruby版本

rbenv local 2.5.8

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Ubuntu下安装Ruby,Rails运行环境发布时间:2022-07-14
下一篇:
[Ruby]使用Ruby抓取网页及加工处理发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap