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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16222738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:54:24  来源:igfitidea点击:

How do I install ruby 2.0.0 correctly on Ubuntu 12.04?

rubyubuntu

提问by Kashiftufail

I have successfully installed rvm, but when I run the following commands

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

sudo apt-get update

Or:

或者:

rvm install 2.0.0

I have the following errors:

我有以下错误:

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

How can I fix these errors?

我该如何修复这些错误?

回答by Pravin Mishra

follow below steps

请按照以下步骤操作

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

回答by gmuraleekrishna

Use rvmto install stable ruby:

使用rvm安装稳定红宝石:

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

or, if you have rvm already, get stable version:

或者,如果您已经有 rvm,请获取稳定版本:

rvm get stable

Install ruby and use the specific version of ruby (remember to use login shell)

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

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

As found on the official RVM website.

正如在官方 RVM 网站上找到的那样

EDIT: As @prem points out run this at first and follow the above steps if there is a public key error

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

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

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

Use rbenvto install ruby:

使用rbenv安装Ruby:

Install necessary dependancies:

安装必要的依赖:

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

Install rbenv:

安装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

Install ruby:

安装红宝石:

rbenv install -v 2.0.0

回答by ThorSummoner

From the travis-cli installation instructions for Ubuntu, the Brightbox Ruby NG(NextGeneration)ppa:

来自travis-cli Ubuntu 的安装说明Brightbox 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

回答by Dirk Conrad Coetsee

Although this answer was accepted, I would strongly recommend using rvm rather. I had nothing but trouble trying to install ruby without it. See e.g. this guide:

尽管此答案已被接受,但我强烈建议您使用 rvm。我在没有它的情况下尝试安装 ruby​​ 时遇到了麻烦。参见例如本指南:

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

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

回答by duma

Any easy way to install ruby is with ruby-install. I had compile errors when building ruby from scratch, but ruby-installencountered no such problems.

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

edit:I've had problems with rvmin the past, and feel I should actively recommend against this. That's just me personally, though. I've had okay luck with rbenv, but always use it in conjunction with ruby-install.

编辑:我过去遇到过问题rvm,觉得我应该积极反对这个。不过,这只是我个人。我的运气还不错rbenv,但总是与ruby-install.

回答by automan

You have some ppa sources enabled that aren't available for your version of Ubuntu. Comment those out in your /etc/apt/sources.list , run sudo apt-get update , and you'll be fine.

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

回答by borracciaBlu

Use rbenv

使用rbenv

The first step is to install some dependencies for Ruby.

第一步是为 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

Installing with rbenvis a simple two step process. First you install rbenv, and then ruby-build:

使用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

gorails.com 上的原始帖子

回答by rubo77

I put @PravinMishra's source into a Gistand now you can simply use this one liner:

我将@PravinMishra的源代码放入Gist 中,现在您可以简单地使用这个衬垫:

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

NOTE:Don't trust my Gist blindly, download the file and look into it before you run it!

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