Mac初心者のボクがMacBook上でRailsを動かせるようになるまで
かなり遠回りした感じもある!少しずつ上手になっていくといいですね.Railsと関係のない部分も多々あるよ.
Mac OS X 10.5.1 の話です.
bashからzshへ
> chsh Changing shell for june29. Password for june29:
そしたらファイルの編集が始まるから
# Changing user information for june29. # Use "passwd" to change the password. ## # Open Directory: /Local/Default ## Shell: /bin/zsh Full Name: june29 Office Location: Office Phone: Home Phone:
Shellのところをzshへのパスにする.
自分リポジトリからdotfilesを持ってくる
http://d.hatena.ne.jp/june29/20070515/1179213618
に書いた感じで.Macでは/Users/USERNAMEがホームディレクトリになる.ここはFinderでもちょくちょく開く場所なので,あまり散らかしたくないなぁと思いました.ファイル名がドットで始まるファイルはFinderには表示されないようなので(表示させることもできるのかな),細かいファイルはそうしておくとよさそう.
> cd > mkdir .dotfiles > svn co http://path/to/repos/dotfiles .dotfiles
シンボリックリンクを張っておしまい.
lsコマンドのオプション
いつものaliasだと怒られた.
# alias ls="ls -aFh --color=auto --show-control-chars" alias ls="ls -aFGh"
表示結果を色付けするには G オプションで.
Xcode 3.0
http://developer.apple.com/tools/download/
からダウンロードしようとしてDMGへのリンクをクリックしたら「No error」とだけ表示された.テラシュール.その後,3種類くらいのエラーメッセージっぽいものと対面して,そして諦めた.
先輩マカーの人たちに聞いてみると「1.1GBもあるファイルをダウンロードするもんじゃないよ!OSのインストールディスクから入れなさい」とのことでした.アドバイスありがとうございます.DVD ! DVD !
なぜかここだけスクリーンショットを撮った.Optional Installsディレクトリの中にXcode Toolsってのがあるので,中身を引っ張りだしてやりました.ついでだと思って
- XcodeTools.mpkg
- Dashcode.mpkg
- WebObjects.mpkg
3つ全部を入れた.XcodeToolsのインストールには20分くらいかかった.あとの2つはすぐ終わる.
これでCコンパイラなど,開発に使いそうな基本的なものが入ったのだと思います.
MacPortsのインストールと最初のお仕事
参考 : http://d.hatena.ne.jp/hakobe932/20061208/1165646618
http://svn.macosforge.org/repository/macports/downloads/MacPorts-1.5.0/
から MacPorts-1.5.0-10.5.dmg をダウンロードしてきて中に入っているインストーラを起動した.次へ次へと進めるとすんなりとインストールが完了したよ.
インストールが終わったら /opt/local にパスを通しておきましょう.続いてアップデートとリストの更新です.
> sudo port -d selfupdate > sudo port -d sync DEBUG: Synchronizing ports tree(s) Synchronizing from rsync://rsync.macports.org/release/ports/ DEBUG: /usr/bin/rsync -rtzv --delete-after rsync://rsync.macports.org/release/ports/ /opt/local/var/macports/sources/rsync.macports.org/release/ports receiving file list ... done devel/gmp/ lang/gcc42/ sent 74 bytes received 288582 bytes 3773.28 bytes/sec total size is 16009564 speedup is 55.46
gemのアップデートとRailsのバージョンアップ
> sudo gem apdate Gems: [capistrano, cgi_multipart_eof_fix, daemons, fastthread, ferret, gem_plugin, highline, libxml-ruby, mongrel] updated > sudo gem install rails --include-dependencies Successfully installed rails-1.2.5
これで大丈夫かな.
MySQLのインストール
MacPortsさんにはいきなり働いてもらいます.
参考 : http://www.fraction.jp/log/archives/2007/10/31/install_mysql_to_leopard
> port search mysql gauche-dbd-mysql databases/gauche-dbd-mysql 0.2.1 Gauche database driver for MySQL mysql3 databases/mysql3 3.23.58 Multithreaded SQL database server mysql4 databases/mysql4 4.1.22 Multithreaded SQL database server mysql5 databases/mysql5 5.0.45 Multithreaded SQL database server mysql5-devel databases/mysql5-devel 5.1.22-rc Multithreaded SQL database server mysqltcl databases/mysqltcl 3.02 Simple API for Mysql-Database and Tcl scripting language. mysqlxx databases/mysqlxx 1.7.35 C++ wrapper for MySQL's C API mysql-connector-java java/mysql-connector-java 5.0.7 MySQL Official JDBC connector for MySQL database. p5-class-dbi-mysql perl/p5-class-dbi-mysql 1.00 Extensions to Class::DBI for MySQL p5-dbd-mysql perl/p5-dbd-mysql 4.005 Perl5 Database Interface to the MySQL database py-mysql python/py-mysql 1.2.2 Python interface to mysql py25-mysql python/py25-mysql 1.2.2 Python interface to mysql rb-dbd-mysql ruby/rb-dbd-mysql 0.0.23 Ruby DBI driver for Mysql. OBSOLETE: please use dbd_mysql variant of rb-dbi rb-mysql ruby/rb-mysql 2.7.3 Ruby API for the Mysql database > sudo port install mysql5
これで無事にインストールできましたが,どうやらvariantsのserverを付加した方が良さそうです.アンインストールはuninstallです.
> port --help Supported commands ------------------ activate, archive, build, cat, cd, checksum, clean, compact, configure, contents, deactivate, dependents, deps, destroot, dir, distcheck, dmg, dpkg, echo, ed, edit, exit, extract, fetch, file, gohome, help, info, install, installed, list, livecheck, location, mirror, mpkg, outdated, patch, pkg, provides, quit, rpm, search, selfupdate, srpm, submit, sync, test, trace, unarchive, uncompact, uninstall, upgrade, url, usage, variants, version, work > sudo port uninstall mysql5 > port variants mysql5 universal darwin_8 server > sudo port install mysql5 +server ---> Fetching mysql5 ---> Verifying checksum(s) for mysql5 ---> Extracting mysql5 ---> Applying patches to mysql5 ---> Configuring mysql5 ---> Building mysql5 with target all ---> Staging mysql5 into destroot ---> Creating launchd control script ########################################################### # A startup item has been generated that will aid in # starting mysql5 with launchd. It is disabled # by default. Execute the following command to start it, # and to cause it to launch at startup: # # sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist ########################################################### ---> Installing mysql5 5.0.45_3+server ****************************************************** * In order to setup the database, you might want to run * sudo -u mysql mysql_install_db5 * if this is a new install ****************************************************** ---> Activating mysql5 5.0.45_3+server ---> Cleaning mysql5
きちんとインストールされたか確認してみる.
> port installed The following ports are currently installed: mysql5 @5.0.45_3+server (active) openssl @0.9.8g_0 (active) zlib @1.2.3_1 (active)
OpenSSLとzlibも一緒に入っています.いらっしゃい!次は,上のログにもある通り,実行しろと言われている処理があるので命令に従う.
> sudo -u mysql mysql_install_db5 Installing MySQL system tables... 071118 22:55:02 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive OK Filling help tables... 071118 22:55:03 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password' /opt/local/lib/mysql5/bin/mysqladmin -u root -h 13.0.168.192.in-addr.arpa password 'new-password' See the manual for more instructions. You can start the MySQL daemon with: cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script! The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com
OK OK と言っているから大丈夫でしょう.そのまま設定ファイルの編集に移ります.
> sudo cp /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf > emacs /opt/local/etc/mysql5/my.cnf # 以下の1行を追加 default-character-set = utf8
2007-12-04 追記
MySQLの文字コードの設定はややこしくて,上記の作業だけじゃ上手くいきません!誤解を与える書き方をしてしまってすみませんでした.
ヽ( ・∀・)ノくまくまー(2006-10-11)に書いてある話をよく読んで設定すると上手くいくと思います!
MySQLの起動と停止
- server付きでインストールしたことにより,launchctlが使えます.
# 起動 > sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist # 停止 > sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist
Railsのdatabase.ymlに書くこと
development: adapter: mysql database: DATABASE username: USERNAME password: PASSWORD socket: /opt/local/var/run/mysql5/mysqld.sock encoding: utf8 host: localhost test: (略) production: (略)
よし
これでRailsアプリを開発できるようになったよ!