This is the way I managed to install Ruby on rails 3.2 with MySQL on Debian/Ubuntu.
Pay
attention: if you had already installed Ruby on rails with SQLite3 and
you just want to add mysql database you can skip some steps, but make
sure to install the required libraries.
1. INSTALL THE NEEDED LIBRARIES
Type the following command in the console:
1. INSTALL THE NEEDED LIBRARIES
Type the following command in the console:
- sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev
2. DOWNLOAD AND INSTALL RUBY 1.9.3
- Download the last version Ruby 1.9.3 in the "Compiling Ruby" section of the web page
- Unzip the archive
- Install running:
- $ ./configure
- $ make
- take a coffee
- $ sudo make install
- Check the successful installation running ruby -v: it should answer with "ruby 1.9.3p..."
- Download ruby gem version 1.8.25 (rubygems-1.8.25.tgz)
- Unzip the archive somewhere
- Put the console in the unzipped folder
- Install running: $ sudo ruby setup.rb
- Check the successful installation running gem -v: it should reply "1.8.25"
4. INSTALL RAILS
- Install Rails running on the console: $ sudo gem install rails
- (it takes a while, don't worry)
- Check if everything is ok using the commands "rails -v" (you should get "rails 3.2.XX") or "gem list"
- Install running on the console: $ sudo apt-get install mysql-client-5.5 mysql-server-5.5
- During the installer it asks for a mysql root-user password (type for ex. admin)
- Try to start and stop the mysql server using the commands:
$ sudo service mysql start
6. INSTALL MYSQL GEM
- In order to install the mysql gem you could use:
- $ sudo gem install mysql2
- $ sudo gem install therubyracer
7. CREATE A NEW RAILS PROJECT
- $ rails new yourappname -d=mysql
- When you see run bundle install wait some seconds.
- Put the console in myapp folder
- It could be useful also to run:
- $ sudo bundle install
8. DATABASE SETTINGS ON THE NEW RAILS APPLICATION
- Open the file myapp/config/database.yml and put your mysql root-user passwordfor the test and development database
- You must leave a blank character after the 'password' keybord. So you should get something like this:
encoding: utf8
reconnect: false
database: myapp_development
pool: 5
username: root
password: your-password
socket: /var/run/mysqld/mysqld.sock
- Start the mysql database using: sudo service mysql start
- Put the console in myapp folder and run: $ rake db:create
- Check the step 12 if you get an error here.
If creates the db is correctly creates, it replies with anything...
- It could be useful to check if the db is created or not: do like this:
$ mysql -u root -p // open mysql console
$ Enter password: type-your-password
mysql> show databases;
and you should find the myapp_test and myapp_development db.
mysql> \q // close mysql console
10. RUN YOUR RAILS APP
- Put the console in myapp folder and run $ rails server
- Open the browser
- http://localhost:3000
- and you should see the Ruby on Rails: welcome page;-)
I suggest you to continue the ROR learning on the official documentation, in particular on the getting started page.
11. SOME USEFUL MYSQL COMMANDS
- $ mysql -u root -p // open mysql console
- mysql> show databases; //show all the databases
- mysql> use database-name; //select a database
- mysql> show tables; //show the tables of the selected db
- mysql> describe table-name; //show the attributes of the selected table
- If you need to change the mysql root password type this command:
- $ mysqladmin -u root -p password enter-your-new-password
- Enter password: enter-your-old-password
12. !! COMMON ISSUES THAT MIGHT OCCUR !!
- Running rake db:create or rake db:migrate you could get the error: Could not find a JavaScript runtime.
- put in the first line of your Rakefile: gem 'therubyracer'
- run sudo bundle install
- Running rake db:create or rake db:migrate you could get the error: uninitialized constant Rake::DSL. The solution is to put in the first line of your Rakefile: require 'rake/dsl_definition'
- In the browser at localhost:3000 you could get the error: "no such file to load -- openssl". The solution is to go through the installation directory of ruby: ruby-1.9.2-p180/ext/openssl and run:
ruby extconf.rb
make
sudo make install
I hope that everything went the right way, check the comments below, feel free to post comments or issues, please provide me a feedback ;-) AND DON'T FORGET TO +1' !
0 comments:
Post a Comment