Installing Ruby on Rails 3.1.1 with MySql on Windows-7 64-bit
2013-08-07 17:48
696 查看
Download
the Savvy Digital Marketer's Guide to Social Content Marketing!.
I recently upgraded my Ruby on Rails installation from Ruby 1.8.7 and Rails 2.3.2 to Ruby 1.9.3 and Rails 3.1.1
There are tons of examples on the internet to make Rails 3.1 work with SqlLite on Windows, but it was constantly failing with mySql for me. I figured out that the following sequence of steps works reliably and all the time.
Download and Install the ruby development kit. DevKit installer is available on the same page where you downloaded Ruby Installer from – http://rubyinstaller.org/downloads/.
Follow the installation instructions from here –https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
Download and Install 32bit version of MySQL community server for Windows from here –http://dev.mysql.com/downloads/mysql/
I
downloaded the 32 bit version of MySQL Server even though my operating system is 64bit. Iwas not able to get the 64bit version work with Rails 3.1’s mysql2 gem.
If
the configuration wizard hangs without showing any progress for more than a minute, kill it and rerun it by executing C:\Program
Files (x86)\MySQL\MySQL Server 5.5\bin\MySQLInstanceConfig.exe. It usually runs fine the second time.
If you see a screen like the one shown below. Everything has worked well so far !
This
is the most important step in the entire process… Copy “C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib\libmysql.dll” to “C:\Ruby193\bin\libmysql.dll”
Open an “Administrative Command Prompt”
Run “gem install rails –v 3.1.1” command to install the rails version 3.1.1. Note that the “v 3.1.1” is very important.
At the time of writing this blog post, Rails version 3.1.2 was out and 3.1.2 had an incompatibility with sprokets on Windows 7. Ensure that you specify version 3.1.1 in the “gem install” command
Run “rails –v” to ensure that correct version of rails is installed
Type the following command as-is from an elevated command prompt. If needed tweak the installation directories to match the paths on your PC.
Note
the single quotes around the entire arguments list. It is important. Also note the double quotes around the mysql installation path. They are also important if the mysql installation path has a white space in it.
gem install mysql2 — ‘–with-mysql-lib=”c:\Program Files (x86)\MySQL\MySQL Server 5.5\lib” –with-mysql-include=”c:\Program
Files (x86)\MySQL\MySQL Server 5.5\include”‘
1. Create a directory for a test project. Say %userprofile%\Documents\RailsTest
2. Run the following command to create a new rails project called “demo” which binds to the mysql server. You should see the following output on the screen
rails new demo –d mysql
3. The demo directory should have the typical Rails application directory structure that looks like the following.
4. Update the …\demo\config\database.ymlfile to match the mysql user name, password and host infomration
Here is a sample configuration.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo_development
pool: 5
username: root
password: root
host: localhost
5. Run rake db:createto create the demo database.
NOTE: rake db:create in most cases should work. However, I have experienced in one case where rake db:create used to mess-up MySql’s user password. If you suddenly see that the mysql user is not able to authenticate after running rake db:create, re-install
mysql and create the database manually on the mysql prompt instead of running the rake task.
6. Run the web server using the following command “rails server”. The inbuilt ralis development server (WEBrick) will start up and start
listening for connections on port 3000.
7. Open a web-browser and point it to http://127.0.0.1:3000 or http://localhost:3000.
You should see a webpage that looks like the following.
8. Click on the “About your application’s environment”. The environment should not show any errors.
Lets create a sample rails scaffold to test if the server is working en-to-end.
1. Generate a scaffold by running the following command
rails g scaffold product name:string description:text price:decimal
2. Run rake db:migrateto create the database tables for the products resource.
3. Open a web browser and navigate to http://127.0.0.1/products.
4. You should see a products listing page – feel free to play around with it – create new products, delete them, edit them, etc.
Hope this blog post gives you a clear guide to go about installing rails on Windows.
Happy Coding !!!
the Savvy Digital Marketer's Guide to Social Content Marketing!.
I recently upgraded my Ruby on Rails installation from Ruby 1.8.7 and Rails 2.3.2 to Ruby 1.9.3 and Rails 3.1.1
There are tons of examples on the internet to make Rails 3.1 work with SqlLite on Windows, but it was constantly failing with mySql for me. I figured out that the following sequence of steps works reliably and all the time.
Step1: Install Ruby 1.9.3
1. Download Ruby Installer (v. 1.9.3-p0) for windows fromhttp://rubyinstaller.org/downloads/ | |
2. Run the Installation program | |
3. Accept the license agreement | |
4. Select the installation path. I chose the default c:\Ruby193. Chose to add Ruby executable to the environment PATH variable. This step is very important.Click Install | |
5. Let the Installation finish | |
6. Click “Finish” to complete the installation | |
7. Open a command prompt and type ruby –vto verify right version of ruby is installed.8. Type gem –v to ensure gem utility is installed9. Run “gem update –system” to ensure that the latest version of gem is installed. |
Step 2: Install Ruby Dev Kit.
Download and Install the ruby development kit. DevKit installer is available on the same page where you downloaded Ruby Installer from – http://rubyinstaller.org/downloads/.Follow the installation instructions from here –https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
Step 3: Install MySQL
Download and Install 32bit version of MySQL community server for Windows from here –http://dev.mysql.com/downloads/mysql/I
downloaded the 32 bit version of MySQL Server even though my operating system is 64bit. Iwas not able to get the 64bit version work with Rails 3.1’s mysql2 gem.
1. Click “Next” on the first installation wizard screen | |
2. Accept the EULA and click “Next” | |
3. Click “Complete” | |
4. Click “Install” | |
5. Let the installation finish | |
6. Click “Finish” |
Step 4: Configure MySQL
If
the configuration wizard hangs without showing any progress for more than a minute, kill it and rerun it by executing C:\Program
Files (x86)\MySQL\MySQL Server 5.5\bin\MySQLInstanceConfig.exe. It usually runs fine the second time.
If you see a screen like the one shown below. Everything has worked well so far !
Step 5: Copy libmysql.dll
This
is the most important step in the entire process… Copy “C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib\libmysql.dll” to “C:\Ruby193\bin\libmysql.dll”
Step 6: Install rails 3.1.1
Open an “Administrative Command Prompt”Run “gem install rails –v 3.1.1” command to install the rails version 3.1.1. Note that the “v 3.1.1” is very important.
At the time of writing this blog post, Rails version 3.1.2 was out and 3.1.2 had an incompatibility with sprokets on Windows 7. Ensure that you specify version 3.1.1 in the “gem install” command
Run “rails –v” to ensure that correct version of rails is installed
Step 7: Install mysql2 gem
Type the following command as-is from an elevated command prompt. If needed tweak the installation directories to match the paths on your PC.Note
the single quotes around the entire arguments list. It is important. Also note the double quotes around the mysql installation path. They are also important if the mysql installation path has a white space in it.
gem install mysql2 — ‘–with-mysql-lib=”c:\Program Files (x86)\MySQL\MySQL Server 5.5\lib” –with-mysql-include=”c:\Program
Files (x86)\MySQL\MySQL Server 5.5\include”‘
Step 8: Test Rails Installation.
1. Create a directory for a test project. Say %userprofile%\Documents\RailsTest2. Run the following command to create a new rails project called “demo” which binds to the mysql server. You should see the following output on the screen
rails new demo –d mysql
3. The demo directory should have the typical Rails application directory structure that looks like the following.
4. Update the …\demo\config\database.ymlfile to match the mysql user name, password and host infomration
Here is a sample configuration.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: demo_development
pool: 5
username: root
password: root
host: localhost
5. Run rake db:createto create the demo database.
NOTE: rake db:create in most cases should work. However, I have experienced in one case where rake db:create used to mess-up MySql’s user password. If you suddenly see that the mysql user is not able to authenticate after running rake db:create, re-install
mysql and create the database manually on the mysql prompt instead of running the rake task.
6. Run the web server using the following command “rails server”. The inbuilt ralis development server (WEBrick) will start up and start
listening for connections on port 3000.
7. Open a web-browser and point it to http://127.0.0.1:3000 or http://localhost:3000.
You should see a webpage that looks like the following.
8. Click on the “About your application’s environment”. The environment should not show any errors.
Step 9: Test a sample Rails Scaffold
Lets create a sample rails scaffold to test if the server is working en-to-end.1. Generate a scaffold by running the following command
rails g scaffold product name:string description:text price:decimal
2. Run rake db:migrateto create the database tables for the products resource.
3. Open a web browser and navigate to http://127.0.0.1/products.
4. You should see a products listing page – feel free to play around with it – create new products, delete them, edit them, etc.
Hope this blog post gives you a clear guide to go about installing rails on Windows.
Happy Coding !!!
相关文章推荐
- Windows下: RubyMine + Ruby On Rails + mysql 搭建开发环境
- How to run 32 bit .NET Windows apps on 64 bit Windows (including with IEExec)
- How To Use MySQL with Your Ruby on Rails Application on Ubuntu 14.04
- Installing Ruby and Railswith RVM on Fedora 14
- Install and Create MySQL ODBC Connector on Windows 7 64 bit
- Installing Active Directory on Windows Server 2008 R2 Enterprise 64-bit
- Ruby on Rails + MySQL在windows64位系统上的配置
- Ubuntu开发ruby on rails(使用windows上mysql)ip地址变动
- 10 steps to get Ruby on Rails running on Windows with IIS FastCGI- 摘自网络
- Ruby On Rails connect with MySQL
- windows 下搭建ruby on rails+Mysql开发环境
- Installing mysql on windows 7 and using ruby on it
- Ruby on Rails Installation on windows xp
- how to test observe with rspec in ruby on rails.
- Installing MySQL on Microsoft Windows Using a noinstall Zip Archive
- Installing MySQL from Source on Windows
- Ruby on rails开发从头来(windows)(二)-创建项目和第一个Hello world (修正原版错误)
- 新人千万不要在 Windows 上使用 Ruby on Rails (整了好久,没整出来,看到这个帖子,直接不整windows了)
- Ruby on rails开发从头来(windows)(一)-使用InstantRails快速搭建Ruby On Rails开发环境
- getting start with rubyOnRails