Elton's Blog

Leopard下手工安装ruby,rails和mysql

by on 八.23, 2009, under Mac, Rails

1. 安装readline
ftp://ftp.gnu.org/gnu/readline/

1
2
3
4
cd readline-6.0
./configure --prefix=/usr/local
make
sudo make install

2. 安装ruby

1
2
3
4
5
6
tar xvjf ruby-1.8.7-p174.tar.bz2
cd ruby-1.8.7-p174
./configure --prefix=/usr/local/ruby --enable-pthread --with-readline-dir=/usr/local --enable-shared
make
sudo make install
sudo make install-doc

使用ruby -v来确认版本安装正确

3. 安装mysql

1
2
3
4
5
6
/configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=max-no-ndb
make
sudo make install
cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var/

mac os x 是靠 launchd 守护进程运行的, 配置文件用的是 PropertyList (XML 格式), 通过观察发现每10秒检查一次, 发现进程不在就启动.

方法是新建 /Library/LaunchDaemons/com.mysql.mysqld.plist 写入如下内容.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
<true />
	<key>Label</key>
	<string>com.mysql.mysqld</string>
	<key>Program</key>
	<string>/usr/local/mysql/bin/mysqld_safe</string>
	<key>RunAtLoad</key>
<true />
	<key>UserName</key>
	<string>mysql</string>
	<key>WorkingDirectory</key>
	<string>/usr/local/mysql</string>
	</dict>
</plist>

加入守护清单
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist

查看清单
launchctl list

解除守护
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

4. 安装mysql的c驱动

http://rubyforge.org/fsr/download.php/51087/mysql-ruby-2.8.1.tar.gz

1
2
3
4
5
tar xzvf mysql-ruby-2.8.1.tar.gz
cd mysql-ruby-2.8.1
ruby extconf.rb --with-mysql-dir=/usr/local/mysql
make
sudo make instal

如果出现类似以下的错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... yes
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

就换用

1
sudo ruby extconf.rb --with-mysql-config




:, , ,

7 Comments for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit my friends!

A few highly recommended friends...