基于mac 开发。
一。安装相应软件:
1.安装mac系统的一些组件
(1).mac 系统更新(主要是更新一些支持ruby的组件)
(2).Install Xcode (去http://developer.apple.com/xcode/下载最新版本的xcode安装)
(3).Install Homebrew
# ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)" # brew install git # brew update
2.安装ImageMagick / MySQL
(1).安装Imagemagick
# brew install imagemagick
(2). 安装MySQL
# brew install mysql #mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp # mkdir -p ~/Library/LaunchAgents (如果有此目录省去此步) #cp "$(brew --prefix mysql)"/com.mysql.mysqld.plist ~/Library/LaunchAgents #launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist #"$(brew --prefix mysql)"/bin/mysql_secure_installation
* Set root password? [Y/n] Y * New password: 123456 * Re-enter new password: 123456 * Remove anonymous users? [Y/n] Y * Disallow root login remotely? [Y/n] Y * Remove test database and access to it? [Y/n] Y * Reload privilege tables now? [Y/n] Y
有问题是不是,没问题,我们下面来解决常见的两个问题,我也遇到了。
问题1:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决办法:
首先关掉mysql :
#launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
然后创建/usr/local/etc/my.cnf文件,内容:
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] bind-address = 127.0.0.1 port = 3306 socket = /tmp/mysql.sock
#launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist执行安装mysql的最后一步:
#"$(brew --prefix mysql)"/bin/mysql_secure_installation
问题2:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)解决办法:首先还是关掉mysql
#launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
然后使用 # mysqld_safe --skip-grant-tables
启动mysql(赋予所有用户全部权限,我们用来改root密码)
再然后,在另外一个客户端(就是另外一个终端界面)执行(用root账户登录)
# mysql -u root
更改root密码
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';刷新mysql权限相关表
FLUSH PRIVILEGES;
3.安装ruby and rails
安装RVM ( Ruby Version Manager )
#bash < <(curl -s https://rvm.beginrescueend.com/install/rvm) #echo "[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm" >> ~/.profile$ . ~/.profile #source ~/.profile
安装REE ( Ruby Enterprise Edition )
rvm install ree
ERROR: Error running './installer -a /Users/ray/.rvm/rubies/ree-1.8.7-2011.03 --no-tcmalloc --dont-install-useful-gems ', please read /Users/ray/.rvm/log/ree-1.8.7-2011.03/install.log ERROR: There has been an error while trying to run the ree installer. Halting the installation.
解决方法有分两种情况
(1).xcode4.2版本以下
# rvm remove ree # export CC=/usr/bin/gcc-4.2 # rvm install --force ree
(2).xcode 4.2版本及以上
这个比较麻烦点,要么把xcode4.2卸载从新装xcode4.1版本,要么自己装gcc。
本人采用第二种方法操作,因为实在是不想卸载重新装,太麻烦。
gcc下载https://github.com/kennethreitz/osx-gcc-installer 下载对应的版本安装。
然后:
#rvm install 1.9.3 #rvm use 1.9.3 #ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.0.0]
好了,ruby安装成功。
然后安装ruby需要的必要gem
# gem install rails # gem install mysql2 # gem install passenger # gem install nokogiri # gem install capistrano # gem install capistrano-ext # gem install delayed_job # gem install hoptoad_notifier # gem install facebooker2 # gem install factory_girl # gem install sphinx
# sudo gem install rails
上面看到了,rail是也安装好了。