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 ...
标题与描述均提到了“ruby on rails安装环境”,这表明文档主要关注的是如何在特定的环境中设置Ruby on Rails。Ruby on Rails(常简称为Rails)是一种用于开发Web应用程序的开源框架,采用Ruby语言编写,遵循MVC...
作为Ruby应用开发中的主流框架之一,Rails可以通过RubyGems轻松安装。执行命令`gem install rails -y`即可一键安装Rails及其所有依赖包。例如: ```bash gem install rails -y ``` 安装完成后,可以使用`gem list`...
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...
- Installing Rails on Windows requires setting up Ruby, installing gems like `bundler`, and configuring the environment. Developers often use tools like RubyInstaller and DevKit for Windows. 2. **...
安装 Mumax 3.9.1 和 Gnuplot 5.2 在 Windows 10 中的步骤指南 在这篇文章中,我们将一步步指导用户安装 Mumax 3.9.1 和 Gnuplot 5.2 在 Windows 10 操作系统中。这篇文章将为用户提供详细的安装步骤和相关知识点,...
This article delves into the details of integrating SAP and Ruby on Rails, focusing specifically on the use of AJAX within Ruby on Rails to enhance user experience. ## Installation Requirements To ...
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
但在此之前,如果你遇到了“Error installing redis: redis requires Ruby version >= 2.3.0”的错误,这意味着Redis需要一个更高版本的Ruby才能安装。在安装Redis之前,请确保你的Ruby版本至少是2.3.0,如果尚未...
在 Windows 平台上进行 Ruby on Rails 开发时,可能会遇到各种各样的安装问题。本文将详细解释一个常见的问题:“在 Windows 下安装或升级 Rails 时,gem 命令提示需要更新 PATH 或下载 DevKit”,并提供详细的解决...
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...
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
1. Open edX平台简介:文档中提到的“Installing, Configuring, and Running the Open edX Platform”是一个运行手册,该手册对如何安装、配置和运行Open edX平台提供了详尽的指导。Open edX平台支持各种在线教育...
根据提供的文件信息,本书《Installing and Configuring Windows Server 2012 Exam Ref 70-410》是一本针对Microsoft认证考试70-410的专业辅导教材。本书由Craig Zacker编写,并由Microsoft Press出版。以下是本书中...
根据给定的文件信息,我们将详细讨论关于Syngress出版的电子书《How to Cheat at Installing, Configuring and Troubleshooting Active Directory and DNS》中所涉及的核心知识点。该书的重点在于为读者提供快速的、...
在多计算机环境中安装BizTalk Server 2010和BAM(业务活动监控)是一项复杂但至关重要的任务,尤其对于寻求高可用性和分离运行时与管理功能的企业来说。以下是对这个过程的详细说明。 **安装高可用性环境** ...
eCos RedBoot guide-A guide for installing and using RedBootdebug and bootstrap firmware.eCos操作系统redboot源码详细说明及使用移植说明