Installing Ruby, Rubygems, Rails, and Mongrel on Mac OS X 10.5 (Leopard)
These are instructions for compiling and installing Ruby, Rubygems, Ruby on Rails, and Mongrel on Mac OS X 10
.5 (Leopard).
If you already know why I write these tutorials, if you already have /usr/local
in your path, if you’ve installed XCode installed already … in other words, if you’re an old-school Hivelogic reader, just click here to jump right to the instructions
.
The FAQ
(Sort Of)
Below I’ll
walk you through getting your system ready for building and compiling
open source software. But before I do, please allow me to answer of few
of the questions I invariably get asked every time I release this type
of do-it-yourself tutorials:
Why would I want to compile this stuff when it ships as part of Leopard?
Good
question! Leopard ships with Ruby 1.8.6 and Rails 1.2.3 – both
respectably recent and stable versions. And it’s easy enough to update
to the latest version of Rails with a single command (sudo gem install rails
if you’re curious).
Then
why roll your own? I expand on the benefits of building your own open
source utilities (like Ruby and Rails) and why where they live is
important in my article entitled Using /usr/local
, but here are a few of the reasons:
- You want to run the latest/greatest versions of available
software and don’t want to wait (or hope) for Apple to release an
update.
- Your want to update, tweak, and customize your own tools while keeping your system “stock” from Apple’s standpoint.
- Apple may decide to modify these utilities during a system update, and doing so may break your stuff.
- You can move or remove the
/usr/local
filesystem, or even transfer it to another machine in one step.
- You’re used to, interested in, or curious about in the compile and build process.
For some people, these reasons are enough to take a few minutes to build your own software.
Why wouldn’t I just use MacPorts or Fink?
Both MacPorts
and Fink
are great projects, and I wholeheartedly support their efforts. I’m also a longtime FreeBSD
geek, and the FreeBSD ports tree
is something I’ve relied upon for ages. So I really get what MacPorts and Fink are about.
On
the other hand, I’m a geek at heart, I don’t mind compiling my own
software, and I like the ability to build just what I need, right when
I need it, without installing or waiting for any additional or
externally-maintained software. If this method sounds like a headache
to you, I know where you’re coming from. MacPorts and Fink provide most
excellent alternatives. Tell them I sent you.
I used your instructions and I got the following error …
Please
don’t email me about it but instead, post your question in the
comments. I try and read and respond as often as I can. When I can’t,
other Hivelogic readers often step in and try to help (they’re a great
bunch), and usually we can figure it out together.
Prerequisites
You will need:
- Mac OS X 10
.5 (Leopard)
- Xcode 3.0 or newer
- Familiarity with (or willingness to use) the Mac OS X
Terminal application
Note:
You will probably need to install Xcode from the Mac OS X
install DVD
/CD (in the Optional Installs -> Xcode folder). You can also download it from Apple’s Developer Connection
free of charge.
Another Note:
These instructions are written for people using the default Mac OS X
shell, bash
.
If you haven’t manually changed your shell from bash, and you didn’t
upgrade to Leopard from something older than Tiger, then you don’t have
anything to worry about. If you’ve taken specific steps to change the
default shell to something other than bash (like tcsh
),
then you’ll need to figure out equivalent syntax to use when setting
paths and environment variables, or just switch back to bash, because
we just roll with bash here. Sorry.
Just In Case
While it’s unlikely that any of these steps
might damage your system somehow, it’s probably a good idea to have a
current backup of everything, just in case (I recommend SuperDuper!
for this by the way, awesome product). So you’re following these
instructions at your own risk, and I’m not liable for anything that
happens.
A Note about sudo
With great power comes great responsibility, so Mac OS X
may prompt you for your password prior to executing some of the
commands you’ll be typing. It may do this only once, or several times
throughout this process. Just re-enter your password as needed.
Using Terminal
You’ll need to launch the Terminal application. It can be found in the /Applications/Utilities
folder.
Each of the lines below appearing in monospaced type should be entered into Terminal, and be followed by the Return key.
Paths
Don’t skip this step!
Mac OS X
, like other UNIX
systems, uses something called a path
to determine where it should look for applications on the command line
(that is, when you’re using the Terminal app). The path is actually an
environment variable, set by a special file that’s automatically
executed when you open a new Terminal window.
We need to make sure that our path is set to look for files in /usr/local
(the place where we’ll be installing the tools) before looking anywhere else. This is important.
To see if the path has been set properly, we can check the contents of the .bash_login
file (the special file hidden in our home folder) for a PATH
line using a text editor. TextMate
, TextWrangler
, BBEdit
, and vi
are all perfectly good options. To open the file with TextMate, for example, we can type:
mate ~/.bash_login
This will open the file if it already exists, or open a blank file if it doesn’t. Add the following line at the very end of the file
:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
Now save and close the file.
It doesn’t matter how many other lines there are in the file, or what they say or do. Just make sure that this line comes last
and you should be fine.
To make sure the changes are picked up correctly, we now need to execute the file with the following command:
. ~/.bash_login
It’s likely there will be no response from the shell here,
just the prompt, but that’s OK, the changes have been picked up and
we’re ready to move on.
You can also close your Terminal and open a new one instead if you’d like.
Note:
You may have noticed that I’ve added MySQL to the path in the line
above. That’s because most users will be installing MySQL later in this
tutorial. If you’re the type to want to use something like SQLite or
PostGreSQL as your database instead of MySQL, you can feel free to omit
the /usr/local/mysql/bin:
bit from the line above, and
replace it with the path to the database of your choice. If this note
doesn’t make sense to you, even if you don’t
plan to install MySQL later, just keep on going … the extra bit in the path statement won’t affect you at all.
Setting Up
I like to create a folder to contain all of
the downloaded files and their respective build folders. I tend to keep
this folder around indefinitely. Source code doesn’t take up much
space, and it’s useful to refer back to later to remind yourself of
previous installation details or techniques, installed versions, for a
fast install at a later time, or in case you want to uninstall
something.
For these examples, we’ll create a folder called src
in the /usr/local
section of the filesystem, and change directories into that folder. It will be our workspace for everything we do here:
sudo mkdir -p /usr/local/src
sudo chgrp admin /usr/local/src
sudo chmod -R 775 /usr/local/src
cd /usr/local/src
You’ll download and compile everything in this new folder.
Ruby
Ok, let’s get started. Unlike previous versions of Mac OS X
,
Leopard has everything you’ll need to compile Ruby. You don’t need to
install any prerequisites. Take these commands and type or paste them
into Terminal:
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz
tar xzvf ruby-1.8.6-p111.tar.gz
cd ruby-1.8.6-p111
./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1
make
sudo make install
cd ..
To verify that Ruby is installed and in your path, just type:
which ruby
You should see:
/usr/local/bin/ruby
If you don’t, you haven’t set your path correctly.
RubyGems
With Ruby installed, we can move on to RubyGems. Same routine:
curl -O http://files.rubyforge.mmmultiworks.com/rubygems/rubygems-1.0.1.tgz
tar xzvf rubygems-1.0.1.tgz
cd rubygems-1.0.1
sudo /usr/local/bin/ruby setup.rb
cd ..
Ruby on Rails
At last, we’re ready to install Rails. RubyGems will handle this for us:
sudo gem install rails
Mongrel and Capistrano get installed the same way:
sudo gem install mongrel
sudo gem install capistrano
There are a handful of other gems you’ll undoubtedly want,
and you can install them one at a time, or all on one line (if you have
a list) like this:
sudo gem install RedCloth termios rspec sake
The MySQL Gem
As of Rails 2.0, the default database system is is now SQLite
, which also ships with Leopard.
Many of us still run MySQL locally though, and want to install the MySQL gem for better Rails integration. If you followed my MySQL for Mac OS X
installation instructions
or used one of the official MySQL distributions, your MySQL lives in /usr/local/mysql
. You can install the gem using the following command:
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
We’re Done
Congratulations, you now have a custom-built, properly installed Ruby on Rails system! You might also like to build your own Subversion client
or run your own MySQL server
too.
分享到:
相关推荐
Ruby on Rails is the revolutionary online programming tool that makes creating functional e-commerce web sites faster and easier than ever. With the intuitive, straightforward nature of Ruby and the ...
Learn the principles behind object-oriented programming and within a few chapters create a fully functional Ruby application. You'll also gain a basic understanding of many ancillary technologies such...
EXECUTABLE DIRECTORY: c:/ruby/bin - RUBYGEMS PLATFORMS: - ruby - x86-mswin32-60 - GEM PATHS: - c:/ruby/lib/ruby/gems/1.8 - C:/Documents and Settings/Administrator/.gem/ruby/1.8 - GEM CONFIGURATION: -...
安装mumax3最全教程
Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...
An error occurred while installing pg (0.19.0), and Bundler cannot continue. Make sure that `gem install pg -v '0.19.0'` succeeds before bundling. 尝试运行以下命令: brew update br
Installing BizTalk Server 2010 and BAM in a Multi-Computer Environment
Windows Me DDK Installing Windows Me Drivers And USB Document
Syngress - How to Cheat at Installing, Configuring and Troubleshooting Active Directory and DNS.pdf
Installing and configuring servers Chapter 2. Configuring server roles and features Chapter 3. Configuring Hyper-V Chapter 4. Deploying and configuring core network services Chapter 5. Installing and...
mcsa考试题库。exam:70-410 。Installing and Configuring Windows Server 2012 R2
MSYS2 is required to build native C/C++ extensions for Ruby and is necessary for Ruby on Rails. Moreover it allows the download and usage of hundreds of Open Source libraries which Ruby gems can ...
Installing and Configuring Openfiler with DRBD and Heartbeat
eCos RedBoot guide-A guide for installing and using RedBootdebug and bootstrap firmware.eCos操作系统redboot源码详细说明及使用移植说明
如果您熟悉 Ruby on Rails 等 Web 框架,我们会采用许多相同的原则并将它们应用于我们的平台。 特别是,我们的 SDK 可以开箱即用,您只需进行最少的配置。 在 Parse 上,您为每个移动应用程序创建一个应用程序。 ...
Redis安装遇到错误解决方案Error installing redis: redis requires Ruby version >= 2.3.0. 先安装rvm,再把ruby版本提升至2.3.0
70 410认证考试辅导书,写的比较浅显易懂,是英文的。
AFF A220 and FAS2700 - Installing and setting up.pdf
原版MSCE 考试用书,也可做为参考用书,比较详细MS.Exam.Ref.70-410.Installing.and.Configuring.Windows.Server.2012.R2.0735684
Git is one of those version control systems - but not just any: Top projects like the Linux Kernel, Ruby On Rails, or jQuery use Git as their version control system of choice. Around the world, in ...