使用 ruby​​-install 应用程序在 Ubuntu 12.04 上安装 ruby​​ 2.1

使用 ruby​​-install 应用程序在 Ubuntu 12.04 上安装 ruby​​ 2.1

我已经阅读了一些关于如何安装 ruby​​ 2.1 的教程。* 我的系统当前有 ruby​​ 1.9.3,我想要最新的。我正在按照以下教程了解如何从此处安装它:http://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you //

到目前为止,这些是我执行的命令:

sudo apt-get install build-essential

wget -O ruby-install-0.5.0.tar.gz \
  https://github.com/postmodern/ruby-install/archive/v0.5.0.tar.gz
tar -xzvf ruby-install-0.5.0.tar.gz
cd ruby-install-0.5.0/
sudo make install

ruby-install ruby 2.1.3
DEPENDENCY ERRORS

一旦我开始 ruby​​-install ruby​​ 2.1.3,我就会遇到这样的问题:

>>> Installing ruby 2.1.3 into /opt/rubies/ruby-2.1.3 ...
>>> Installing dependencies for ruby 2.1.3 ...
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package libyaml-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libgdbm-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libncurses5-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libffi-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'libyaml-dev' has no installation candidate
E: Package 'libgdbm-dev' has no installation candidate
E: Unable to locate package libreadline-dev
E: Package 'libncurses5-dev' has no installation candidate
E: Package 'libffi-dev' has no installation candidate
!!! Installing dependencies failed!

好吧,它说我缺少所有这些依赖项。我怎样才能让他们安装它,这样它就可以停止抱怨?为什么没有一个命令只说“好吧,您缺少这些依赖项,让我为您安装它们(是/否)?

答案1

以下是根据官方说明在基于 Debian 的系统中安装 Ruby 2.1 的命令Ruby Dockerfile。顺便说一句,您可以使用 Docker 来避免这种痛苦。

# Update your system packages
apt-get update 

# Install some basic dependencies
# Few of thems aren't needed but won't hurt anyway
apt-get install -y \
    autoconf \
    build-essential \
    imagemagick \
    libbz2-dev \
    libcurl4-openssl-dev \
    libevent-dev \
    libffi-dev \
    libglib2.0-dev \
    libjpeg-dev \
    libmagickcore-dev \
    libmagickwand-dev \
    libmysqlclient-dev \
    libncurses-dev \
    libpq-dev \
    libreadline-dev \
    libsqlite3-dev \
    libssl-dev \
    libxml2-dev \
    libxslt-dev \
    libyaml-dev \
    zlib1g-dev \

apt-get install -y curl procps

RUBY_MAJOR="2.1"
RUBY_VERSION="2.1.5"

apt-get install -y bison ruby

mkdir -p /usr/src/ruby
curl -SL "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.bz2" | tar -xjC /usr/src/ruby --strip-components=1
cd /usr/src/ruby
autoconf
./configure --disable-install-doc
make -j"$(nproc)"
apt-get purge -y --auto-remove bison ruby
make install
rm -r /usr/src/ruby

GEM_HOME="/usr/local/bundle"
PATH=$PATH:$GEM_HOME/bin
gem install bundler
bundle config --global path "$GEM_HOME"
bundle config --global bin "$GEM_HOME/bin"

正如您可以想象的那样,某些命令需要在 sudo 模式下输入。

此时您应该已经安装了 Ruby 2.1.5。要验证,请输入ruby -v.

注意:我尚未对此进行测试,因此请随时提供反馈。

相关内容