如何在Ubuntu 12.04上正确安装ruby 2.0.0?

问题描述 投票:78回答:8

我已经成功安装了rvm,但是当我运行以下命令时

sudo apt-get update

要么:

rvm install 2.0.0

我有以下错误:

W: Failed to fetch http://ppa.launchpad.net/cheleb/blender-svn/ubuntu/dists/precise/main/source/Sources  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/cheleb/blender-svn/ubuntu/dists/precise/main/binary-amd64/Packages  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/cheleb/blender-svn/ubuntu/dists/precise/main/binary-i386/Packages  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/ferramroberto/oneiric/ubuntu/dists/precise/main/source/Sources  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/ferramroberto/oneiric/ubuntu/dists/precise/main/binary-amd64/Packages  404  Not Found

W: Failed to fetch http://ppa.launchpad.net/ferramroberto/oneiric/ubuntu/dists/precise/main/binary-i386/Packages  404  Not Found

我该如何解决这些错误?

ruby ubuntu
8个回答
190
投票

按照以下步骤

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz
tar -xvzf ruby-2.0.0-p481.tar.gz
cd ruby-2.0.0-p481/
./configure --prefix=/usr/local
make
sudo make install

55
投票

Use rvm to install stable ruby:

curl -sSL https://get.rvm.io | bash -s stable --ruby

或者,如果你已经有rvm,获得稳定版本:

rvm get stable

安装ruby并使用特定版本的ruby(记得使用login shell)

/bin/bash --login
rvm install 2.0.0
rvm use 2.0.0
rvm rubygems latest
ruby --version

如在the official RVM website上找到的。

编辑:正如@prem指出的那样,首先运行此命令,如果存在公钥错误,请按照上述步骤操作

gpg --keyserver hkp://keys.gnupg.net --recv-keys \ 409B6B1796C275462A1703113804BB82D39DC0E3

Use rbenv to install ruby:

安装必要的依赖项:

sudo apt-get update && sudo apt-get install git-core curl zlib1g-dev \
build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev \
sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev \
python-software-properties libffi-dev

安装rbenv

cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

安装红宝石:

rbenv install -v 2.0.0

32
投票

travis-cli installation instructions for UbuntuBrightbox Ruby NG(NextGeneration) ppa:

$ sudo apt-get install python-software-properties
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
$ sudo apt-get install ruby2.1 ruby-switch
$ sudo ruby-switch --set ruby2.1

7
投票

虽然这个答案被接受了,但我强烈建议使用rvm。我没有遇到麻烦在没有它的情况下安装ruby。参见例如本指南:

https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm


3
投票

安装ruby的任何简单方法都是使用ruby-install。从头开始构建ruby时我遇到了编译错误,但ruby-install没遇到这样的问题。

编辑:我过去曾遇到rvm的问题,觉得我应该积极推荐这个。不过,那只是我个人而已。我和rbenv运气好,但总是和ruby-install一起使用它。


2
投票

您启用了一些不适用于您的Ubuntu版本的ppa源。在你的/etc/apt/sources.list中评论那些,运行sudo apt-get update,你会没事的。


1
投票

使用rbenv

第一步是为Ruby安装一些依赖项。

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties

使用rbenv进行安装是一个简单的两步过程。首先安装rbenv,然后安装ruby-build:

cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.0.0
rbenv global 2.0.0
ruby -v

The original post on gorails.com


1
投票

我把@ PravinMishra的来源放到Gist中,现在你可以简单地使用这个内衬:

wget -O - https://git.io/vvkI4 | bash

注意:不要盲目信任我的Gist,下载文件并在运行之前查看它!

© www.soinside.com 2019 - 2024. All rights reserved.