Bye Bye Macports, Welcome Homebrew

Definition
Homebrew: The missing package manager for OS X

Why? well, the reality is, macports is not that good anymore.
Once you have many packages installed and start updating, everything start to break apart, lot’s of failing packages.

Homebrew is very easy to install, it’s fast and simple. That means you can make your own homebrew formula for your package so easily. oh, and homebrew is in ruby! :)

Back to topic, this is you how you get rails with mysql up and running with homebrew and rvm.

Clean up

To make sure to have a clean install, I recommend removing any previous .rvm installation and previous Xcode.

# rm -rf ~/.rvm/
# sudo rm -rf /Developer

1. Xcode

Install Xcode from AppStore. it’s 3 GB download so it may take a while.
after it’s downloaded it will not install automatically, you need to open Applications and install again from there. the name will be “Install Xcode”

Update: If you don’t want to download and install huge XCODE (3.0GB) :
https://github.com/kennethreitz/osx-gcc-installer
It allows you to install the essential compilers, GCC, LLVM, etc.
PS: I have not tested it
Thanks JP for the tip.

2. Install HomeBrew

UPDATE: in the comments some people recommended to do create the folder “/usr/local/Cellar” before hand, due to some bug on homebrew.

mkdir -p /usr/local/Cellar
#  /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

Installation instructions: https://github.com/mxcl/homebrew/wiki/installation

3. install RVM

#  bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

then after RVM is installed run these two 'one-line' commands, the second command will reload your bash with RVM.

# echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
# source ~/.bash_profile

Details instructions: http://beginrescueend.com/rvm/install/

4. Install ruby 1.9.3

OS X Lion comes with Ruby-1.8.7-p249, but we all want ruby 1.9.2/1.9.3 right?

# rvm install 1.9.3-p0
# rvm use ruby-1.9.3-p0
# gem install rails bundler unicorn pg
... and so on ...

I tested both ruby-1.9.3-head and ruby-1.9.3-p0, and it works well with all my apps. Ruby 1.9.3 is faster than 1.9.2 booting rails, and way way faster than 1.8.7. So let's use the lastest Stable Ruby (1.9.3-p0)

See: Rails booting a lot faster.

# rvm install 1.9.3-p0

NOTE: For Heroku I recommend you to use ruby-1.9.2-p290, specially if you use the command "heroku db:pull"

Optionally you might want to install GIT, wget, ack, imagemagick and any other mighty software tools for daily use.

Example apps I'm usually required to install:

# brew install git ack wget curl redis memcached libmemcached colordiff imagemagick nginx sqlite libxml2 libxslt readline v8 rsync sphinx lzma geoip lzo

5. Install Mysql

# brew install mysql

one-line command:

# mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

Once mysql is installed you might want it to load automatically each time you start your mac.

# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/Cellar/mysql/5.5.14/com.mysql.mysqld.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

*check that the version I use here is 5.5.14

6. Troubleshooting:

if you have problems with mysql "cannot connect to /tmp/mysql.sock"
then create a file /usr/local/etc/my.cnf and add this:

[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock

if encounter errors with homebrew run this command and follow recommendations:

# brew doctor

update: If you end up with Segmentation fault or cannot install Ruby-1.8.7, you might want to try this solution:

# export CC=/usr/bin/gcc-4.2
# rvm install ruby-1.8.7

by the way this is my /usr/local/etc/my.cnf optimized file, when using this file you may have to recreate your db

# mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
[client]
port = 3306
socket = /tmp/mysql.sock 

[mysqld]
event_scheduler = ON
skip-character-set-client-handshake
collation_server = utf8_unicode_ci
character_set_server = utf8 

bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
max_connections = 20

table_open_cache = 256
max_allowed_packet = 32M
binlog_cache_size = 1M
max_heap_table_size = 64M 

read_buffer_size = 2M
read_rnd_buffer_size = 2M
sort_buffer_size = 4M
join_buffer_size = 512k

thread_cache_size = 2
thread_concurrency = 2
query_cache_size = 16M
query_cache_limit = 2M 

default-storage-engine = INNODB
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M 

# MyISAM Options 

key_buffer_size = 32M
bulk_insert_buffer_size = 32M
myisam_sort_buffer_size = 32M
myisam_max_sort_file_size = 256M
myisam_repair_threads = 1
myisam_recover 

# INNODB Options
innodb_additional_mem_pool_size = 8M
innodb_buffer_pool_size = 64M
innodb_thread_concurrency = 2
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 8M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 120
innodb_file_per_table

[mysqldump]
quick
max_allowed_packet = 16M 

[mysql]
no-auto-rehash 

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 64M
read_buffer = 16M
write_buffer = 16M

[mysqlhotcopy]
interactive-timeout 

EDITED (Feb 10, 2012):
* updated for new RVM
* source .bash_profile after editing it.
* decreased memory settings for mysql
* using ruby-1.9.3-p0
* fixed minor bugs

VN:F [1.9.14_1148]
Rating: 7.9/10 (12 votes cast)
VN:F [1.9.14_1148]
Rating: +3 (from 5 votes)
Installing Rails on OS X Lion with HomeBrew, RVM and Mysql, 7.9 out of 10 based on 12 ratings

  62 Responses to “Installing Rails on OS X Lion with HomeBrew, RVM and Mysql”

  1. Thanks for the guide. I have one question regarding to mysql; /usr/local/Cellar/mysql/5.5.15: 6277 files, 217M as you can see it shows 5.5.15 as the version, but on the mysql site the version is 5.5.20.
    Why does't get the official latest version?

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  2. [...] Installing Rails on OS X Lion with HomeBrew, RVM and Mysql | Ruby, Rails, OSX and Linux fun – [...]

  3. I continue to have the following error when I run ‘rvm install 1.9.3. I’ve been at it for 10 hours with no solution:

    Error running ‘make ‘, please read /Users/esharpless/.rvm/log/ruby-1.9.3-p0/make.log
    There has been an error while running make. Halting the installation.

    Help is appreciated.

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  4. On item #3 above I got a warning that the command given to install rvm is deprecated.


    # bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

    Deprecated command, please use:

    bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

    Also between step’s 3 and 4, the user will need to reload their bash for step 4 to work:


    source ~/.bash_profile

    Running that works, so far. :)

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  5. thanks for the updates. just updated article to reflect new version of RVM.
    cheers

    VN:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  6. Update for XCode 4.2

    Error logs read as follows on Ruby 1.9.3 install:

    configure: WARNING: unrecognized options: –with-libyaml
    checking build system type… x86_64-apple-darwin11.2.0
    checking host system type… x86_64-apple-darwin11.2.0
    checking target system type… x86_64-apple-darwin11.2.0
    checking whether the C compiler works… no
    configure: error: in `/Users/chadhuber/.rvm/src/ruby-1.9.3-p0′:
    configure: error: C compiler cannot create executables
    See `config.log’ for more details

    C compiler in XCode 4.2 was altered so you must now run as follows

    $ rvm install 1.9.3 –with-gcc=clang

    via stackoverflow http://stackoverflow.com/questions/8032824/cant-install-ruby-under-lion-with-rvm-gcc-issues

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  7. Hey,

    If you’re having problems getting the installation to work from the rvm install ruby-1.9.3-p0 command check out this comment: http://stackoverflow.com/questions/8032824/cant-install-ruby-under-lion-with-rvm-gcc-issues

    In particular, when using the newest version of XCode you need to explicitly state its a clang compiler

    rvm instal ruby-1.9.3-p0 –with-gcc=clang

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: +1 (from 1 vote)
  8. I just did an install of Lion from scratch and it looks like the Xcode install has changed. It doesn’t appear to install the command line tools unless you go to the download section and click install. Even then, I had problems with installing REE over RVM. I’m starting over from scratch now and will try that Xcode alternative download. I’ll let you know!

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  9. cool, let us know how it goes.
    also, have a look at 2 comments above yours, Chad suggested to do “rvm install 1.9.3 –with-gcc=clang”

    VN:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VN:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  10. I just did a Lion install from scratch and things look good using the Xcode alternative. I got a warning while install ree-1.8.7-head, but it still appeared to work. The warning was:


    Error running 'patch -F 25 -p1 -N -f <"/Users/tom/.rvm/patches/ree/1.8.7/tcmalloc.patch"', please read /Users/tom/.rvm/log/ree-1.8.7-head/patch.apply.tcmalloc.log

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  11. I’m receiving an error on Step #4 rvm install 1.9.3-p0

    The error I’m receiving is below.

    Error running ‘ ./configure –prefix=/Users/*****/.rvm/rubies/ruby-1.9.3-p0 –enable-shared –disable-install-doc –with-libyaml –with-opt-dir=/Users/*****/.rvm/usr ‘, please read /Users/*****/.rvm/log/ruby-1.9.3-p0/configure.log
    There has been an error while running configure. Halting the installation.

    Help is appreciated.

    Thanks
    Mike

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)
  12. Hey All,

    With Xcode 4.3 apple makes the command-line tools an optional install when you get xcode from the app-store (thats why the size is only 1.35 gb).

    To install the command tools open xcode => preferences => downloads => and press install command-line tools.

    This should fix all of the errors you are getting.

    VA:F [1.9.14_1148]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.14_1148]
    Rating: 0 (from 0 votes)

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 Ruby, Rails, OSX and Linux fun Suffusion theme by Sayontan Sinha

Switch to our mobile site