How to install Ruby on Mac/change Ruby source in China

Source: Internet
Author: User
Tags connection reset install cocoapods ruby on rails

The tailor made for the Basix users among. If you've been itching to try out Ruby and/or Rails, if the Terminal are somewhat new to you, your may find that even the PR Ocess of installing it can generate countless confusing errors. This article would detail the exact steps you need to follow for get Ruby up and running on your Mac.

Step 1-RVM

What are interested to know are that Ruby comes preinstalled on your Mac. might Don ' t believe me? Open the Terminal and type:

1 ruby -v

Likely, the version number would return 1.8.7 . While you might is tempted to stick with the, 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 so you require. Plus, if you ' re just starting out with Ruby, don ' t use a old version; You want 1.9.2!

These days, RVM are 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 vers Ion of Ruby, all the the-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-tra Ce 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 was returned when you run the This command, make sure, then you have Git installed. Don ' t worry, it ' s easy to setup!

Step 2-load RVM into the Shell

Give a few seconds to install, and next, we need to make RVM available to the shell. We ' ll do the updating our ~/.bash_profile file.

12 cd~/sudovim .bash_profile

Note that the we ' re using VIM to update the this file, which can is a bit confusing at first. Feel free to open this file in any code editor your prefer. Maybe you want mate .bash_profile . Also, note that, if the this file is 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 the press to switch into first i Insert Mode . Once the line had been pasted, press Escape , and then to :wq! Save and close the file. If you ' re using a different code editor and then you know "what to do!

Step 3-restart Terminal

Just to is safe, let's restart Terminal to make sure that everything took effect. To ensure this RVM is correctly installed, type:

1 rvm

You should see a long list of commands that is available to you. Good job; That's the out of the.

Step 4-download the Latest Version of Xcode

From my experiences, the biggest gotcha are when you try to install a new version of Ruby with RVM, and you ' re met with a h Andful of confusing errors. Most of the time, the result of the Apple's Xcode not being installed on your system, or, if it's, not being the Curr ENT 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 would take some time to download. Once it does, though, run the install process, and, when finished, close Xcode. You shouldn ' t need-restart your computer, but, if it keeps your in the good graces of the church, go ahead and does 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 ...

0102030405060708091011121314 $ RVM list known # MRI Rubies 1.8.6[-p420] 1.8.6- head 1.8.7[-p352] 1.8.7- head 1.9.1-p378 1.9.1[-p431] 1.9.1- head 1.9.2-p180 1.9.2[-p290] 1.9.2- head ruby- head

For we needs, let's install Ruby 1.9.2

1 rvm install1.9.2

That's 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 would help Y OU debug it. But, before doing so, type: to rvm notes determine if you've forgotten to install any dependencies.

Once the installation have 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-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 had 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 was identical to the what do 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:

12 irb2 + 2

The next step is for install any gems this require. For example, if you want to work with Ruby on Rails:

1 gem installrails

Or possibly Sinatra:

1 gem installsinatra

important:  Note that I ' m not Using  sudo  to install these gems. This is a big  no-no   When the working with RVM. From The official docs:

Running commands as root, another user in another shell and hence all of the setup that RVM have Ignored while the command runs under sudo (such things as gem_home, etc ...). So-to-reiterate, as soon as you ' sudo ' is running as the root system user which would clear out your environment as we ll as any files it creates is not able to being modified by your user and would result in strange things happening. (You'll start to think this someone has a voodoo doll of your application ...) "

Advertisementconclusion

If This tutorial seemed incredibly easy to your, that's because it wasn ' t intended for you. Not everyone was comfortable with the command line, and not everyone installs Ruby without first being met with a huge crop of errors. Hopefully, this article would help a bit. And, again, if you ' re still have trouble, leave a comment, and we ' ll do your best to help you out!

Alternatively to RVM, your also might look into rbenv, which, though quite new, is quickly gaining popularity.

Installation commands,sudo gem install cocoapods

The wall is blocked. This is a mistake.

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)

This is because Ruby's software source rubygems.org because of the use of Amazon's cloud service, or the wall: you need to update the source of Ruby, as follows.

Could not find a valid gem ' cocoapods ' (>= 0) in any repository

$ gem sources-l (view the source of the current ruby)
$ gem Sources--remove https://rubygems.org/
$ gem sources-a https://ruby.taobao.org/
$ gem sources-l

View the current Ruby software source

cuiwenlongdemac-mini:~ cuiwenlong$ gem sources-l*** current sources ***https://ruby.taobao.org/

After adding the Ruby source, install it again and succeed

How to install Ruby on Mac/change Ruby source in China

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.