How to install ruby on mac/ change ruby source in china
his one is tailor made for the Basix users among you. If you've been itching to try out Ruby and/or Rails, if the Terminal is somewhat new to you, you may find that even the process of installing it can generate countless confusing errors. This article will detail the exact steps you need to follow to get Ruby up and running on your Mac.
Step 1 - RVM
What you might be interested to know is that Ruby comes preinstalled on your Mac. Don't believe me? Open the Terminal and type:
|
1
|
ruby -v |
Likely, the version number will return 1.8.7. While you might be tempted to stick with that, you probably shouldn't for a couple reasons:
- Old versions of the OS shipped with a buggy version of Ruby
- RVM provides the flexibility to use any version of Ruby that you require. Plus, if you're just starting out with Ruby, don't use an old version; you want 1.9.2!
These days, RVM is the way the cool kids install Ruby, and that's what we'll use.
"RVM lets you deploy each project with its own completely self-contained and dedicated environment--from the specific version of ruby, all the way down to the precise set of required gems to run your application. Having a precise set of gems also avoids the issue of version conflicts between projects, which can cause difficult-to-trace errors and hours of hair loss. "
Open the Terminal, and type:
|
1
|
$ \curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled # Or, --ruby=1.9.3 |
If an error is returned when you run this command, make sure that you have Git installed. Don't worry, it's easy to setup!
Step 2 - Load RVM into the Shell
Give that a few seconds to install, and next, we need to make RVM available to the shell. We'll do this by updating our ~/.bash_profile file.
|
1
2
|
cd ~/sudo vim .bash_profile |
Note that we're using Vim to update this file, which can be a bit confusing at first. Feel free to open this file in any code editor your prefer. Maybe you want to use mate .bash_profile. Also, note that, if this file does not exist, you should create it manually. Paste the following to the bottom of the page.
|
1
|
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. |
If you're using Vim, you'll need to press i to switch into Insert Mode first. Once the line has been pasted, press Escape, and then :wq! to save and close the file. If you're using a different code editor, then you know what to do!
Step 3 - Restart Terminal
Just to be safe, let's restart Terminal to make sure that everything took effect. To ensure that RVM is correctly installed, type:
|
1
|
rvm |
You should see a long list of commands that are available to you. Good job; that part is out of the way.
Step 4 - Download the Latest Version of Xcode
From my experiences, the biggest gotcha is when you try to install a new version of Ruby with RVM, and you're met with a handful of confusing errors. Most of the time, this is the result of Apple's Xcode not being installed on your system, or, if it is, not being the current version.
You can download Xcode from Apple's App Store. Search for "xcode" and click the install button.

You might want to fix yourself some lunch, as this large file will take some time to download. Once it does, though, run the install process, and, when finished, close Xcode. You shouldn't need to restart your computer, but, if it keeps you in the good graces of the church, go ahead and do so.
Step 5 - Download Ruby 1.9.2
Next, restart Terminal, and type:
|
1
|
rvm list known |
You'll see a long list of versions...
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
$ rvm list known# MRI Rubies1.8.6[-p420]1.8.6-head1.8.7[-p352]1.8.7-head1.9.1-p3781.9.1[-p431]1.9.1-head1.9.2-p1801.9.2[-p290]1.9.2-headruby-head... |
For our needs, let's install Ruby 1.9.2
|
1
|
rvm install 1.9.2 |
That shouldn't take but a moment.
If you still receive an error at this point, leave a comment below with your error message, and the rest of us will help you debug it. But, before doing so, type:
rvm notesto determine if you've forgotten to install any dependencies.
Once the installation has completed, we need to tell RVM which version of Ruby we currently want to use:
|
1
|
rvm use 1.9.2 |
Next, test it by checking the version number:
|
1
|
ruby -v |
On my computer, this returns ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]. Good job, you're now using Ruby 1.9.2. There's just one last thing to deal with.
Step 6 - Make 1.9.2 the Default
If you restart Terminal, and type ruby -v again, you'll likely find that it has defaulted back to the system version of Ruby: 1.8.7. That's no good! Let's be sure to make 1.9.2 the default.
|
1
|
rvm --default use 1.9.2 |
This bit is identical to what we did just a moment ago - the only difference being that we've specified that 1.9.2 should be the default.
Step 7 - Finished. Begin Installing Gems
And that's it! You're all set to go! If you'd like to experiment with Ruby's syntax, type:
|
1
2
|
irb2 + 2 |
The next step is to install any gems that you require. For example, if you want to work with Ruby on Rails:
|
1
|
gem install rails |
Or possibly Sinatra:
|
1
|
gem install sinatra |
Important: Note that I'm not using sudo to install these gems. This is a big no-no when working with RVM. From the official docs:
"When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. (You will start to think that someone has a voodoo doll of your application...)"
Conclusion
If this tutorial seemed incredibly easy to you, that's because it wasn't intended for you. Not everyone is comfortable with the command line, and not everyone installs Ruby without first being met with a huge crop of errors. Hopefully, this article will help a bit. And, again, if you're still having trouble, leave a comment, and we'll do our best to help you out!
Alternatively to RVM, you also might look into rbenv, which, though quite new, is quickly gaining popularity.
安装命令 -> sudo gem install cocoapods
墙挡了.出这个错
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/cocoapods-0.39.0.gemspec.rz)
这是因为ruby的软件源rubygems.org因为使用亚马逊的云服务,还是墙..,需要更新一下ruby的源,过程如下:
Could not find a valid gem 'cocoapods' (>= 0) in any repository
$ gem sources -l (查看当前ruby的源)
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://gems.ruby-china.org/
$ gem sources -l
查看当前ruby的软件源
cuiwenlongdeMac-mini:~ cuiwenlong$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
加进ruby源之后,就再次安装,成功了
cuiwenlongdeMac-mini:~ cuiwenlong$ sudo gem install cocoapods
Password:
Fetching: nap-1.0.0.gem (100%)
Successfully installed nap-1.0.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: minitest-5.8.3.gem (100%)
Successfully installed minitest-5.8.3
Fetching: tzinfo-1.2
How to install ruby on mac/ change ruby source in china的更多相关文章
- How to Install Xcode, Homebrew, Git, RVM, Ruby & Rails on Snow Leopard, Lion, Mountain Lion, and Mavericks
After following many outdated and incomplete instructions for setting up a web development environme ...
- Mac OS Ruby安装 使用RVM
访问http://www.ruby-lang.org/en/downloads/ 使用第三方工具安装ruby,经过了解,在mac下可以使用macports和rvm安装ruby. 经过实际操作觉得rvm ...
- MAC 安装Ruby On Rails
MAC 安装Ruby On Rails 对于新入门的开发者,如何安装 Ruby, Ruby Gems 和 Rails 的运行环境可能会是个问题,本页主要介绍如何用一条靠谱的路子快速安装 Ruby 开发 ...
- ruby 版本管理RVM (ruby version manager)
macOS. 自带的ruby 版本目录权限比较高, 经常有很多 操作需要权限而不能执行 虽然 macOS 自带了一个 ruby 环境,但是是系统自己使用的,所以权限很小,只有 system. 而/Li ...
- Install Docker on Mac OS X(转)
Install Docker on Mac OS X You can install Docker using Boot2Docker to run docker commands at your c ...
- Install wget in Mac OS X Without Homebrew or MacPorts
May 22, 2012 - 31 Comments The command line tool wget lets you retrieve a group of files from FTP an ...
- 安装Ruby、多版本Ruby共存、Ruby安装慢问题
rbenv rbenv可以管理多个版本的ruby.可以分为3种范围(或者说不同生效作用域)的版本: local版:本地,针对各项目范围 global版:全局,没有shell和local版时使用glob ...
- Install Ansible on Mac OSX
from: https://devopsu.com/guides/ansible-mac-osx.html and : https://devopsu.com/guides/ansible-post- ...
- Install Python on Mac (Anaconda)
Install Python on Mac (Anaconda) 标签(空格分隔): 运维 This blog is copy from the link: https://medium.com/@G ...
随机推荐
- 编写单例的 dojo class
define([ "dojo/_base/declare" ],function( declare ){ var TimeChartService = declare(" ...
- C#中“貌似”跳出while(true)死循环
当程序第一次执行到Read()函数时,程序会被阻塞,然后输入字符,Enter之后程序被激活,windows平台会自动在输入字符之后加入回车符和换行符,此时输入流中就有三个字符,然而read每次只读取一 ...
- 使用Rails 4.2+ 测试异步邮件系统
[导读]异步测试总是一个很大的问题,邮件发送测试更是让很多开发同学不知道从哪里入手.在新版的Rails里,这类测试在很大程度上被简化了. 以下为译文 在编写需要发送邮件的应用时,控制器是绝不能被阻塞的 ...
- c# 获取mac地址的2种方法
和大家分享下,互相学习一下吧.第一个获取方法好像获取不到mac地址,我用了第二种方法可以获取到.希望知道的可以说下为什么. 1,首先要添加引用:using System.Management; 2,代 ...
- CodeIgniter 错误: In order to use the Session class you are required to set an encryption key
CodeIgniter SESSION 第一次用 session 遇到这个错误 , 说是要加一个密钥才可以使用,加就加吧, 打开 config.php 找到以下代码 /*|------------- ...
- JavaScript基础之函数与数组
函数 函数的基本概念 为完成某一功能的程序指令(语句)的集合,称为函数.有的程序员把函数称为方法,希望大家不要被这两个名词搞晕了. 函数分为:自定义函数.系统函数(经常查看js帮助手册). j ...
- Badboy录制
摘要 Badboy是一个强大的工具,被设计用于测试和开发复杂的动态应用.Badboy功能丰富(包括一个捕获/重播接口,强大的压力测试支持,详细的报告.图形)使得测试和开发更加容易. Badboy是用来 ...
- linux下如何查看主机的外网ip地址
在linux下如果我们使用的是nat方式上网.通过ifconfig命令查看到的ip地址往往是内网地址 那么如何查看主机在互联网上使用的公网IP呢?我们可以在命令行下使用curl命令实现这个功能. [r ...
- 开始使用Mac OS X——写给Mac新人
本文转自博客园:http://www.cnblogs.com/chijianqiang/archive/2011/08/03/2126593.html 写这篇文档的原因有两个,一.身边使用Mac的朋友 ...
- lintcode:整数排序||
题目 给一组整数,按照升序排序.使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法. 解题 归并排序 public class Solution { /** * @param ...