Google Translate

Saturday, May 25, 2013

Installing RVM, Ruby 2, Rails 3, MySQL on OS X 10.8

ALERT! For Ruby on Rails developers only.

FYI this is more for my reference than anything else. Use at your own risk.

My environment:
  • Mac OS X 10.8.3
  • Intel Core i5
  • XCode 4.6.2 with command line tools
As of this blog, after running all commands, you should end up with:
  • RVM 1.20.12
  • Ruby 2.0.0-p195 + default gems
  • Rails 3.2.13 + associated gems
  • MySQL 5.6.11 (64-bit) using mysql2 gem (version 0.3.11)
First, download and install MySQL.
  1. Temporarily allow software installation from anywhere.
    1. Open System Preferences --> Security & Privacy.
    2. Click the lock icon at bottom-left. When prompted, enter your (administrator) password.
    3. Remember your current setting, i.e. "Mac App Store", "Mac App Store and identified developers" or "Anywhere".
    4. If it is not already selected, click the "Anywhere" radio button. Press "Allow From Anywhere" in the popup.
  2. Download MySQL.
    1. In your web browser, go to https://dev.mysql.com/downloads/mysql/
    2. Download the latest version of 64-bit MySQL as a DMG (as of this blog, it is "Mac OS X ver. 10.7 (x86, 64-bit), DMG Archive", the rest of the steps will use names based on this version).
  3. Install MySQL.
    1. Double-click the downloaded disk image, "mysql-5.6.11-osx10.7-x86_64.dmg".
    2. Double-click "mysql-5.6.11-osx10.7-x86_64.pkg". Install without any customization.
    3. Double-click "MySQL.prefPane". Install for all users on your computer.
    4. Double-click "MySQLStartupItem.pkg". Install without any customization.
    5. Eject the "mysql-5.6.11-osx10.7-x86_64" disk image.
  4. Restart MySQL.
    1. Open System Preferences --> MySQL.
    2. Press the "Stop MySQL Server" button. Enter your (administrator) password if prompted.
    3. If MySQL Server Instance is still running, you need to shut it down in Terminal.
      1. Open Terminal.
      2. Run this command:
        $ sudo /usr/local/mysql/bin/mysqladmin shutdown
        Enter your (administrator) password if prompted.
    4. Press "Start MySQL Server" button. Enter your (administrator) password if prompted.
  5. Reset software installation permission.
    1. Open System Preferences --> Security & Privacy.
    2. Click the lock icon at bottom-left, if it is still locked. When prompted, enter your (administrator) password.
    3. Under "Allow applications downloaded from", choose your previous setting, i.e. "Mac App Store", "Mac App Store and identified developers" or "Anywhere" radio button.
    4. Close System Preferences.
Now, run all of the following commands in OS X's Terminal.
  1. Start a new Terminal session (start a new tab with Cmd-T).
  2. Update permissions.
    $ sudo chmod o-w /usr/local
  3. Install RVM with stable release of Ruby.
    $ \curl -L https://get.rvm.io | bash -s stable --ruby
  4. Start a new Terminal session (start a new tab with Cmd-T).
  5. Update RVM settings.
    $ source /Users//.rvm/scripts/rvm
    $ rvm requirements
  6. Verify RVM.
    $ type rvm | head -n 1
    rvm is a function
  7. Verify Ruby.
    $ rvm current
    ruby-2.0.0-p195
    $ ruby -v
    ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
  8. Verify gem directory.
    $ rvm gemdir
    /Users/<home>/.rvm/gems/ruby-2.0.0-p195
  9. Update Rubygem (to be on the safe side).
    $ gem update --system
  10. Install Rails.
    $ gem install rails
  11. Verify Rails.
    $ rails -v
    Rails 3.2.13
  12. Verify GCC.
    $ gcc -v
    Using built-in specs.
    Target: i686-apple-darwin11
    Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~28/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~28/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
    Thread model: posix
    gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
  13. Verify MySQL.
    $ mysql -V
    mysql  Ver 14.14 Distrib 5.5.20, for osx10.6 (i386) using readline 5.1
  14. Symlink MySQL dynamic library.
    $ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
  15. Update mysql_config. (I use vim as my text editor.)
    $ sudo vim /usr/local/mysql/bin/mysql_config
    1. Go to line 119.
    2. Copy-and-paste lines 119 and 120.
    3. Comment lines 119 and 120.
    4. Line 121: remove -Wno-null-conversion -Wno-unused-private-field
    5. Line 122: remove -Wno-null-conversion -Wno-unused-private-field
    6. So lines 119-122 should now be:
      #cflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
      #cxxflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
      cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
      cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
    7. Save and exit.
  16. Install mysql2 gem.
    $ sudo env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
    If mysql2 gem still fails to install:
    1. Uninstall mysql2 gem.
      $ gem uninstall mysql2 -a
    2. Delete MySQL's files and folders.
      $ sudo rm /usr/local/mysql
      $ sudo rm -rf /usr/local/mysql*
      $ sudo rm -rf /Library/StartupItems/MySQLCOM
      $ sudo rm -rf /Library/PreferencePanes/My*
      $ sudo vim /etc/hostconfig
      $ sudo rm -rf /Library/Receipts/mysql*
      $ sudo rm -rf /Library/Receipts/MySQL*
    3. Re-download and re-install MySQL.
    4. Go back to step 14 and continue from there.
Hope that works for you too!

No comments:

Post a Comment