MacLochlainns Weblog

Michael McLaughlin's Technical Blog

Site Admin

Archive for April, 2015

MySQLdb Manage Columns

without comments

Sometimes trying to keep a post short and to the point raises other questions. Clearly, my Python-MySQL Program post over the weekend did raise a question. They were extending the query example and encountered this error:

TypeError: range() integer end argument expected, got tuple.

That should be a straight forward error message because of two things. First, the Python built-in range() function manages a range of numbers. Second, the row returned from a cursor is actually a tuple (from relational algebra), and it may contain non-numeric data like strings and dates.

The reader was trying to dynamically navigate the number of columns in a row by using the range() function like this (where row was a row from the cursor or result set):

    for j in range(row):

Naturally, it threw the type mismatch error noted above. As promised, the following Python program fixes that problem. It also builds on the prior example by navigatung an unknown list of columns. Lines 16 through 31 contain the verbose comments and programming logic to dynamically navigate the columns of a row.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
 
# Import sys library.
import MySQLdb
import sys
 
try:
  # Create new database connection.
  db = MySQLdb.connect('localhost','student','student','studentdb')
  # Create a result set cursor.
  rs = db.cursor()
  rs.execute("SELECT item_title, item_subtitle, item_rating FROM item")
  # Assign the query results to a local variable.
  for i in range(rs.rowcount):
    row = rs.fetchone()
    # Initialize variable for printing row as a string.
    data = ""
    # Address an indefinite number of columns.
    count = 0
    for j in range(len(row)):
      # Initialize column value as an empty string.
      datum = ""
      # Replace column values when they exist.
      if str(row[count]) != 'None':
        datum = str(row[count])
      # Append a comma when another column follows.
      if count == len(row) - 1:
        data += datum
      else:
        data += datum + ", "
      count += 1
    # Print the formatted row as a string.
    print data
except MySQLdb.Error, e:
  # Print the error.
  print "ERROR %d: %s" % (e.args[0], e.args[1])
  sys.exit(1)
finally:
  # Close the connection when it is open.
  if db:
    db.close()

There are a couple Python programming techniques that could be perceived as tricks. Line 24 checks for a not null value by explicitly casting the column’s value to a string and then comparing its value against the string equivalent for a null. The MySQLdb returns a 'None' string for null values by default. The if-block on lines 27 through 30 ensure commas aren’t appended at the end of a row.

While the for-loop with a range works, I’d recommend you write it as a while-loop because its easier to read for most new Python programmers. You only need to replace line 20 with the following to make the change:

20
    while (count < len(row)):

Either approach generates output like:

The Hunt for Red October, Special Collectornulls Edition, PG
Star Wars I, Phantom Menace, PG
Star Wars II, Attack of the Clones, PG
Star Wars II, Attack of the Clones, PG
Star Wars III, Revenge of the Sith, PG-13
The Chronicles of Narnia, The Lion, the Witch and the Wardrobe, PG
RoboCop, , Mature
Pirates of the Caribbean, , Teen
The Chronicles of Narnia, The Lion, the Witch and the Wardrobe, Everyone
MarioKart, Double Dash, Everyone
Splinter Cell, Chaos Theory, Teen
Need for Speed, Most Wanted, Everyone
The DaVinci Code, , Teen
Cars, , Everyone
Beau Geste, , PG
I Remember Mama, , NR
Tora! Tora! Tora!, The Attack on Pearl Harbor, G
A Man for All Seasons, , G
Hook, , PG
Around the World in 80 Days, , G
Harry Potter and the Sorcerer's Stone, , PG
Camelot, , G

As always, I hope this helps those looking for clarity.

Written by maclochlainn

April 13th, 2015 at 10:05 pm

Perl-MySQL Program

with 2 comments

Configuring Perl to work with MySQL is the last part creating a complete Fedora Linux LAMP stack for my students. Perl is already installed on Fedora Linux.

I’ve also shown how to use PHP, Python, and Ruby languages to query a MySQL database on Linux. After installing this additional Perl DBI library, my students will have the opportunity to choose how they implement their LAMP solution.

You can find the Perl version with the following version.pl program:

1
2
3
4
#!/usr/bin/perl -w
 
# Print the version.
print "Perl ".$]."\n";

The first line lets you call the program without prefacing the perl program because it invokes a subshell of perl by default. You just need to ensure the file has read and execute privileges to run. It prints:

Perl 5.018004

You need to install the perl-DBD-MySQL library to enable Perl to work with MySQL. The following command loads the library:

yum install -y perl-DBD-MySQL

It prints the following log file:

Loaded plugins: langpacks, refresh-packagekit
Resolving Dependencies
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.024-1.fc20 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package               Arch          Version                Repository     Size
================================================================================
Installing:
 perl-DBD-MySQL        x86_64        4.024-1.fc20           fedora        142 k
 
Transaction Summary
================================================================================
Install  1 Package
 
Total download size: 142 k
Installed size: 332 k
Downloading packages:
perl-DBD-MySQL-4.024-1.fc20.x86_64.rpm                      | 142 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Installing : perl-DBD-MySQL-4.024-1.fc20.x86_64                           1/1 
  Verifying  : perl-DBD-MySQL-4.024-1.fc20.x86_64                           1/1 
 
Installed:
  perl-DBD-MySQL.x86_64 0:4.024-1.fc20                                          
 
Complete!

The following item_query.pl Perl program is consistent with the PHP, Python, and Ruby examples provided in other blog posts. It shows you how to use the Perl DBI library to query and return a data set.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w
 
# Use the DBI library.
use DBI;
use strict;
use warnings;
 
# Create a connection.
my $dbh = DBI->connect("DBI:mysql:database=studentdb;host=localhost:3306","student","student",{'RaiseError' => 1});
 
# Create SQL statement.
my $sql = "SELECT item_title FROM item";
 
# Prepare SQL statement.
my $sth = $dbh->prepare($sql);
 
# Execute statement and read result set.
$sth->execute() or die $DBI::errstr;
while (my @row = $sth->fetchrow_array()) {
  my $item_title = $row[0];
  print "$item_title\n";
}
 
# Close resources.
$sth->finish();

You call it like this from the present working directory:

./mysql_query.pl

It returns:

The Hunt for Red October
Star Wars I
Star Wars II
Star Wars II
Star Wars III
The Chronicles of Narnia
RoboCop
Pirates of the Caribbean
The Chronicles of Narnia
MarioKart
Splinter Cell
Need for Speed
The DaVinci Code
Cars
Beau Geste
I Remember Mama
Tora! Tora! Tora!
A Man for All Seasons
Hook
Around the World in 80 Days
Harry Potter and the Sorcerer's Stone
Camelot

Alternatively, there’s a different syntax for lines 20 and 21 that you can use when you’re returning multiple columns. It replaces the two statements inside the while loop as follows:

20
21
  my ($item_title, $item_rating) = @row;
  print "$item_title, $item_rating\n";

It returns:

The Hunt for Red October, PG
Star Wars I, PG
Star Wars II, PG
Star Wars II, PG
Star Wars III, PG13
The Chronicles of Narnia, PG
RoboCop, Mature
Pirates of the Caribbean, Teen
The Chronicles of Narnia, Everyone
MarioKart, Everyone
Splinter Cell, Teen
Need for Speed, Everyone
The DaVinci Code, Teen
Cars, Everyone
Beau Geste, PG
I Remember Mama, NR
Tora! Tora! Tora!, G
A Man for All Seasons, G
Hook, PG
Around the World in 80 Days, G
Harry Potter and the Sorcerer's Stone, PG
Camelot, G

As always, I hope this helps those learning how to use Perl and Linux against the MySQL Database. If you want a nice tutorial on Perl and MySQL, check The tutorialspoint.com web site.

Written by maclochlainn

April 13th, 2015 at 2:14 am

Python-MySQL Program

with 4 comments

This post works through the Python configuration of Fedora instance, and continues the configuration of my LAMP VMware instance. It covers how you add the MySQL-python libraries to the Fedora instance, and provides the students with one more language opportunity for their capstone lab in the database class.

A standard Fedora Linux distribution installs Python 2.7 by default. Unfortunately, the MySQL-python library isn’t installed by default. You can verify the Python version by writing and running the following version.py program before installing the MySQL-python library:

1
2
3
4
5
# Import sys library.
import sys
 
# Print the Python version.
print sys.version

You can run the version.py program dynamically like this from the current working directory:

python version.py

It will print the following:

2.7.5 (default, Nov  3 2014, 14:26:24) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)]

If you modify the program by adding the following first line

1
2
3
4
5
6
7
#!/usr/bin/python
 
# Import sys library.
import sys
 
# Print the Python version.
print sys.version

Provided you’ve set the file permissions to read and execute, you can run the program by simply calling version.py like this from the present working directory:

./version.py

You can install the MySQL-python library with the yum utility like this:

yum install -y MySQL-python

It shows you the following output:

Loaded plugins: langpacks, refresh-packagekit
mysql-connectors-community                                  | 2.5 kB  00:00     
mysql-tools-community                                       | 2.5 kB  00:00     
mysql56-community                                           | 2.5 kB  00:00     
pgdg93                                                      | 3.6 kB  00:00     
updates/20/x86_64/metalink                                  |  12 kB  00:00     
updates                                                     | 4.9 kB  00:00     
updates/20/x86_64/primary_db                                |  13 MB  00:04     
(1/2): updates/20/x86_64/updateinfo                         | 1.9 MB  00:02     
(2/2): updates/20/x86_64/pkgtags                            | 1.4 MB  00:02     
Resolving Dependencies
--> Running transaction check
---> Package MySQL-python.x86_64 0:1.2.3-8.fc20 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package              Arch           Version               Repository      Size
================================================================================
Installing:
 MySQL-python         x86_64         1.2.3-8.fc20          fedora          82 k
 
Transaction Summary
================================================================================
Install  1 Package
 
Total download size: 82 k
Installed size: 231 k
Downloading packages:
MySQL-python-1.2.3-8.fc20.x86_64.rpm                        |  82 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Installing : MySQL-python-1.2.3-8.fc20.x86_64                             1/1 
  Verifying  : MySQL-python-1.2.3-8.fc20.x86_64                             1/1 
 
Installed:
  MySQL-python.x86_64 0:1.2.3-8.fc20                                            
 
Complete!

After installing the MySQL-python library, you can call the following mysql_connect.py program from the local directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
 
# Import sys library.
import MySQLdb
import sys
 
try:
  # Create new database connection.
  db = MySQLdb.connect('localhost','student','student','studentdb')
  # Query the version of the MySQL database.
  db.query("SELECT version()")
  # Assign the query results to a local variable.
  result = db.use_result()
  # Print the results.
  print "MySQL Version: %s " % result.fetch_row()[0]
except MySQLdb.Error, e:
  # Print the error.
  print "ERROR %d: %s" % (e.args[0], e.args[1])
  sys.exit(1)
finally:
  # Close the connection when it is open.
  if db:
    db.close()

Like the version.py program, set the file permissions to read and execute and call , you can run the program by simply calling mysql_connect.py program like this from the present working directory:

./mysql_connect.py

The mysql_connect.py program displays:

MySQL Version: 5.6.24

After verifying the MySQL connection, you can query actual data with the following mysql_queryset.py program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/python
 
# Import sys library.
import MySQLdb
import sys
 
try:
  # Create new database connection.
  db = MySQLdb.connect('localhost','student','student','studentdb')
  # Create a result set cursor.
  rs = db.cursor()
  rs.execute("SELECT item_title FROM item")
  # Assign the query results to a local variable.
  rows = rs.fetchall()
  # Print the results.
  for row in rows:
    print row
except MySQLdb.Error, e:
  # Print the error.
  print "ERROR %d: %s" % (e.args[0], e.args[1])
  sys.exit(1)
finally:
  # Close the connection when it is open.
  if db:
    db.close()

You call the mysql_queryset.py file from the present working directory like this:

./mysql_queryset.py

It prints the following:

('The Hunt for Red October',)
('Star Wars I',)
('Star Wars II',)
('Star Wars II',)
('Star Wars III',)
('The Chronicles of Narnia',)
('RoboCop',)
('Pirates of the Caribbean',)
('The Chronicles of Narnia',)
('MarioKart',)
('Splinter Cell',)
('Need for Speed',)
('The DaVinci Code',)
('Cars',)
('Beau Geste',)
('I Remember Mama',)
('Tora! Tora! Tora!',)
('A Man for All Seasons',)
('Hook',)
('Around the World in 80 Days',)
("Harry Potter and the Sorcerer's Stone",)
('Camelot',)

You can substantially improve on the behavior of the prior example by handling each row one at a time. The following mysql_query.py program reads through the cursor result set one row at a time:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
 
# Import sys library.
import MySQLdb
import sys
 
try:
  # Create new database connection.
  db = MySQLdb.connect('localhost','student','student','studentdb')
  # Create a result set cursor.
  rs = db.cursor()
  rs.execute("SELECT item_title FROM item")
  # Assign the query results to a local variable.
  for i in range(rs.rowcount):
    row = rs.fetchone()
    print row[0]
except MySQLdb.Error, e:
  # Print the error.
  print "ERROR %d: %s" % (e.args[0], e.args[1])
  sys.exit(1)
finally:
  # Close the connection when it is open.
  if db:
    db.close()

You call the mysql_query.py with the following syntax:

./mysql_query.py

It returns the following result set:

The Hunt for Red October
Star Wars I
Star Wars II
Star Wars II
Star Wars III
The Chronicles of Narnia
RoboCop
Pirates of the Caribbean
The Chronicles of Narnia
MarioKart
Splinter Cell
Need for Speed
The DaVinci Code
Cars
Beau Geste
I Remember Mama
Tora! Tora! Tora!
A Man for All Seasons
Hook
Around the World in 80 Days
Harry Potter and the Sorcerer's Stone
Camelot

As always, I hope this helps those looking for this type of solution. The Python tutorial web site teaches you more about the Python Programming Language. You may also find the TutorialsPoint.com site useful while you’re learning and using Python. The MySQLdb User’s Guide teaches more about working writing Python-MySQL library. The MySQLdb implements the Python Database API Specification v2.0.

Written by maclochlainn

April 12th, 2015 at 6:36 pm

MySQL JSON Functions

with 3 comments

What the MySQL team is doing with JSON (JavaScript Object Notation) in MySQL 5.7 is great! The MySQL Server Blog (Rick Hillegas and Dag Wanvik) published two key articles about new JSON functions. If you don’t follow these, let me highlight them as a set:

Most folks know how important JSON is to web development. I like the following visual that highlights it. It was provided as a comment to this earlier Popular Programming Language post by Michael Farmer. Clearly, JavaScript is popular because it’s critical to effective web development. If you’re new to JSON, check out Adam Khoury’s JSON tutorial set on YouTube.

PopularCode2014

If you want the original graphic, you can find it here. It’s always to hard to keep up with the technology, isn’t it? 🙂

Written by maclochlainn

April 11th, 2015 at 11:36 am

Ruby-MySQL Program

with 6 comments

After you install Ruby and build the Rails framework, you need to create the mysql gem. This blog post shows you how to create the mysql gem and how to write a simple Ruby program that queries the MySQL database.

The first step creates the mysql gem for Ruby programming:

gem install mysql

It should show you the following:

Fetching: mysql-2.9.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql-2.9.1
Parsing documentation for mysql-2.9.1
Installing ri documentation for mysql-2.9.1
Done installing documentation for mysql after 0 seconds
1 gem installed

After you install the mysql Ruby Gem, you can write and test a test.rb Ruby program that tests a MySQL database connection. The simplest complete code looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Include Ruby Gem libraries.
require 'rubygems'
require 'mysql'
 
begin
  # Create new database connection.
  db = Mysql.new('localhost','student','student','studentdb')
  # Print connected message.
  puts "Connected to the MySQL database server."
rescue Mysql::Error => e
  # Print the error.
  puts "ERROR #{e.errno} (#{e.sqlstate}): #{e.error}"
  puts "Can't connect to the MySQL database specified."
  # Signal an error.
  exit 1
ensure
  # Close the connection when it is open.
  db.close if db
end

You can run the program with the following syntax:

ruby test.rb

The program prints “Connected to the MySQL database server.” when there’s a student user with a student password that’s authorized to connect to the studentdb database. If any of the values are invalid when creating the connection, the program prints “Can’t connect to the MySQL database specified.”

Having tested the connection, the next query.rb program tests the connection by returning values from a query:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Include Ruby Gem libraries.
require 'rubygems'
require 'mysql'
 
# Begin block.
begin
  # Create a new connection resource.
  db = Mysql.new('localhost','student','student','studentdb1')
  # Create a result set.
  rs = db.query('SELECT item_title FROM item')
  # Read through the result set hash.
  rs.each_hash do | row |
    puts "#{row['item_title']}"
  end
  # Release the result set resources.
  rs.free
rescue Mysql::Error => e
  # Print the error.
  puts "ERROR #{e.errno} (#{e.sqlstate}): #{e.error}"
  puts "Can't connect to MySQL database specified."
  # Signal an error.
  exit 1
ensure
  # Close the connection when it is open.
  db.close if db
end

You can test it with the following command-line syntax:

ruby query.rb

It returns a data set like this from the item table of my video store example:

+---------------------------------------+
| item_title                            |
+---------------------------------------+
| The Hunt for Red October              |
| Star Wars I                           |
| Star Wars II                          |
| Star Wars II                          |
| Star Wars III                         |
| The Chronicles of Narnia              |
| RoboCop                               |
| Pirates of the Caribbean              |
| The Chronicles of Narnia              |
| MarioKart                             |
| Splinter Cell                         |
| Need for Speed                        |
| The DaVinci Code                      |
| Cars                                  |
| Beau Geste                            |
| I Remember Mama                       |
| Tora! Tora! Tora!                     |
| A Man for All Seasons                 |
| Hook                                  |
| Around the World in 80 Days           |
| Harry Potter and the Sorcerer's Stone |
| Camelot                               |
+---------------------------------------+
22 rows in set (0.00 sec)

You need the ruby interpreter to run them. You can make the programs standalone operations by putting the following line as the first line in your Ruby programs.

1
#!/usr/bin/ruby

Then, you can run the program like this if they have read and execute privileges and are located in the present working directory where you issue the following command:

./mysql_query.rb

If you want to work with individual columns, please check this subsequent post that shows how you can access individual columns. As always, I hope this helps those trying to get things working.

After posting this somebody asked for books that could help them learn how to write Ruby programs. While books are nice and listed below, I’d start with the tryruby.org web site.

I’d recommend the following books because …

  • The Ruby Programming Language is 7 years old now and only covers Ruby 1.8 and 1.9, but its written by David Flanagan and the creator of the Ruby Programming Language – Yukihiro Matsumoto.
  • Programming Ruby 1.9 & 2.0: The Pragmatic Programmer’s Guide is more current and a well balanced approach at learning how to write Ruby programs.
  • The Well-Grounded Rubyist is the most current book and teaches you how to think about writing Ruby beyond just the syntax. As a Manning book, you can purchase the physical copy and automatically get a downloadable ebook. It’s certainly the best value for the money option provided you already know how to program in at least one other object-oriented programming language.

Written by maclochlainn

April 11th, 2015 at 2:35 am

Install Ruby on Fedora

with 4 comments

I use a Fedora 20 VM image to teach Oracle and MySQL technology. Last week, I expanded the Fedora VM image to support a full LAMP stack. This blog shows you how to install Ruby on Fedora and successfully generate the Rails gems.

Connect as the root user and use yum to install the libraries. My approach is by library or small groups. Naturally, you start with the ruby library.

yum install ruby

You will see the following:

Loaded plugins: langpacks, refresh-packagekit
mysql-connectors-community                                  | 2.5 kB  00:00     
mysql-tools-community                                       | 2.5 kB  00:00     
mysql56-community                                           | 2.5 kB  00:00     
pgdg93                                                      | 3.6 kB  00:00     
updates/20/x86_64/metalink                                  |  14 kB  00:00     
updates                                                     | 4.9 kB  00:00     
(1/3): mysql56-community/20/x86_64/primary_db               |  80 kB  00:00     
(2/3): pgdg93/20/x86_64/primary_db                          |  80 kB  00:00     
(3/3): updates/20/x86_64/primary_db                         |  13 MB  00:06     
(1/2): updates/20/x86_64/pkgtags                            | 1.4 MB  00:01     
(2/2): updates/20/x86_64/updateinfo                         | 1.9 MB  00:01     
Resolving Dependencies
--> Running transaction check
---> Package ruby.x86_64 0:2.0.0.353-16.fc20 will be installed
--> Processing Dependency: ruby-libs(x86-64) = 2.0.0.353-16.fc20 for package: ruby-2.0.0.353-16.fc20.x86_64
--> Processing Dependency: rubygem(bigdecimal) >= 1.2.0 for package: ruby-2.0.0.353-16.fc20.x86_64
--> Processing Dependency: ruby(rubygems) >= 2.0.3 for package: ruby-2.0.0.353-16.fc20.x86_64
--> Processing Dependency: /usr/bin/ruby for package: ruby-2.0.0.353-16.fc20.x86_64
--> Processing Dependency: libruby.so.2.0()(64bit) for package: ruby-2.0.0.353-16.fc20.x86_64
--> Running transaction check
---> Package ruby-libs.x86_64 0:2.0.0.353-16.fc20 will be installed
---> Package rubygem-bigdecimal.x86_64 0:1.2.0-16.fc20 will be installed
---> Package rubygems.noarch 0:2.1.11-115.fc20 will be installed
--> Processing Dependency: rubygem(rdoc) >= 4.0.0 for package: rubygems-2.1.11-115.fc20.noarch
--> Processing Dependency: rubygem(psych) >= 2.0.0 for package: rubygems-2.1.11-115.fc20.noarch
--> Processing Dependency: rubygem(io-console) >= 0.4.1 for package: rubygems-2.1.11-115.fc20.noarch
---> Package rubypick.noarch 0:1.1.1-1.fc20 will be installed
--> Running transaction check
---> Package rubygem-io-console.x86_64 0:0.4.2-16.fc20 will be installed
---> Package rubygem-psych.x86_64 0:2.0.0-16.fc20 will be installed
--> Processing Dependency: libyaml-0.so.2()(64bit) for package: rubygem-psych-2.0.0-16.fc20.x86_64
---> Package rubygem-rdoc.noarch 0:4.0.1-2.fc20 will be installed
--> Processing Dependency: rubygem(json) < 2 for package: rubygem-rdoc-4.0.1-2.fc20.noarch
--> Processing Dependency: rubygem(json) >= 1.4 for package: rubygem-rdoc-4.0.1-2.fc20.noarch
--> Processing Dependency: ruby(irb) for package: rubygem-rdoc-4.0.1-2.fc20.noarch
--> Running transaction check
---> Package libyaml.x86_64 0:0.1.6-2.fc20 will be installed
---> Package ruby-irb.noarch 0:2.0.0.353-16.fc20 will be installed
---> Package rubygem-json.x86_64 0:1.7.7-101.fc20 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package                 Arch        Version                 Repository    Size
================================================================================
Installing:
 ruby                    x86_64      2.0.0.353-16.fc20       updates       65 k
Installing for dependencies:
 libyaml                 x86_64      0.1.6-2.fc20            updates       55 k
 ruby-irb                noarch      2.0.0.353-16.fc20       updates       86 k
 ruby-libs               x86_64      2.0.0.353-16.fc20       updates      2.8 M
 rubygem-bigdecimal      x86_64      1.2.0-16.fc20           updates       77 k
 rubygem-io-console      x86_64      0.4.2-16.fc20           updates       48 k
 rubygem-json            x86_64      1.7.7-101.fc20          fedora        60 k
 rubygem-psych           x86_64      2.0.0-16.fc20           updates       75 k
 rubygem-rdoc            noarch      4.0.1-2.fc20            fedora       288 k
 rubygems                noarch      2.1.11-115.fc20         updates      224 k
 rubypick                noarch      1.1.1-1.fc20            updates      6.3 k
 
Transaction Summary
================================================================================
Install  1 Package (+10 Dependent packages)
 
Total download size: 3.7 M
Installed size: 13 M
Is this ok [y/d/N]: y
Downloading packages:
(1/11): ruby-2.0.0.353-16.fc20.x86_64.rpm                   |  65 kB  00:00     
(2/11): libyaml-0.1.6-2.fc20.x86_64.rpm                     |  55 kB  00:00     
(3/11): ruby-irb-2.0.0.353-16.fc20.noarch.rpm               |  86 kB  00:00     
(4/11): rubygem-io-console-0.4.2-16.fc20.x86_64.rpm         |  48 kB  00:00     
(5/11): rubygem-json-1.7.7-101.fc20.x86_64.rpm              |  60 kB  00:00     
(6/11): rubygem-psych-2.0.0-16.fc20.x86_64.rpm              |  75 kB  00:00     
(7/11): rubypick-1.1.1-1.fc20.noarch.rpm                    | 6.3 kB  00:00     
(8/11): rubygem-bigdecimal-1.2.0-16.fc20.x86_64.rpm         |  77 kB  00:01     
(9/11): rubygem-rdoc-4.0.1-2.fc20.noarch.rpm                | 288 kB  00:00     
(10/11): ruby-libs-2.0.0.353-16.fc20.x86_64.rpm             | 2.8 MB  00:01     
(11/11): rubygems-2.1.11-115.fc20.noarch.rpm                | 224 kB  00:01     
--------------------------------------------------------------------------------
Total                                              1.4 MB/s | 3.7 MB  00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Installing : ruby-libs-2.0.0.353-16.fc20.x86_64                          1/11 
  Installing : libyaml-0.1.6-2.fc20.x86_64                                 2/11 
  Installing : rubygem-bigdecimal-1.2.0-16.fc20.x86_64                     3/11 
  Installing : rubygem-json-1.7.7-101.fc20.x86_64                          4/11 
  Installing : rubygem-psych-2.0.0-16.fc20.x86_64                          5/11 
  Installing : rubygem-rdoc-4.0.1-2.fc20.noarch                            6/11 
  Installing : ruby-irb-2.0.0.353-16.fc20.noarch                           7/11 
  Installing : rubypick-1.1.1-1.fc20.noarch                                8/11 
  Installing : ruby-2.0.0.353-16.fc20.x86_64                               9/11 
  Installing : rubygems-2.1.11-115.fc20.noarch                            10/11 
  Installing : rubygem-io-console-0.4.2-16.fc20.x86_64                    11/11 
  Verifying  : rubygem-io-console-0.4.2-16.fc20.x86_64                     1/11 
  Verifying  : rubygem-rdoc-4.0.1-2.fc20.noarch                            2/11 
  Verifying  : rubygems-2.1.11-115.fc20.noarch                             3/11 
  Verifying  : rubygem-bigdecimal-1.2.0-16.fc20.x86_64                     4/11 
  Verifying  : ruby-libs-2.0.0.353-16.fc20.x86_64                          5/11 
  Verifying  : rubygem-json-1.7.7-101.fc20.x86_64                          6/11 
  Verifying  : rubygem-psych-2.0.0-16.fc20.x86_64                          7/11 
  Verifying  : rubypick-1.1.1-1.fc20.noarch                                8/11 
  Verifying  : ruby-2.0.0.353-16.fc20.x86_64                               9/11 
  Verifying  : libyaml-0.1.6-2.fc20.x86_64                                10/11 
  Verifying  : ruby-irb-2.0.0.353-16.fc20.noarch                          11/11 
 
Installed:
  ruby.x86_64 0:2.0.0.353-16.fc20                                               
 
Dependency Installed:
  libyaml.x86_64 0:0.1.6-2.fc20                                                 
  ruby-irb.noarch 0:2.0.0.353-16.fc20                                           
  ruby-libs.x86_64 0:2.0.0.353-16.fc20                                          
  rubygem-bigdecimal.x86_64 0:1.2.0-16.fc20                                     
  rubygem-io-console.x86_64 0:0.4.2-16.fc20                                     
  rubygem-json.x86_64 0:1.7.7-101.fc20                                          
  rubygem-psych.x86_64 0:2.0.0-16.fc20                                          
  rubygem-rdoc.noarch 0:4.0.1-2.fc20                                            
  rubygems.noarch 0:2.1.11-115.fc20                                             
  rubypick.noarch 0:1.1.1-1.fc20                                                
 
Complete!

After you install ruby, you need to install the MySQL and Ruby development libraries, like this:

yum -y install gcc mysql-devel ruby-devel rubygems
Loaded plugins: langpacks, refresh-packagekit
Package gcc-4.8.3-7.fc20.x86_64 already installed and latest version
Package rubygems-2.1.11-115.fc20.noarch already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.6.24-1.fc20 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) = 5.6.24-1.fc20 for package: mysql-community-devel-5.6.24-1.fc20.x86_64
---> Package ruby-devel.x86_64 0:2.0.0.353-16.fc20 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.23-1.fc20 will be updated
--> Processing Dependency: mysql-community-libs(x86-64) = 5.6.23-1.fc20 for package: mysql-community-client-5.6.23-1.fc20.x86_64
---> Package mysql-community-libs.x86_64 0:5.6.24-1.fc20 will be an update
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.24-1.fc20 for package: mysql-community-libs-5.6.24-1.fc20.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.23-1.fc20 will be updated
--> Processing Dependency: mysql-community-client(x86-64) = 5.6.23-1.fc20 for package: mysql-community-server-5.6.23-1.fc20.x86_64
---> Package mysql-community-client.x86_64 0:5.6.24-1.fc20 will be an update
---> Package mysql-community-common.x86_64 0:5.6.23-1.fc20 will be updated
---> Package mysql-community-common.x86_64 0:5.6.24-1.fc20 will be an update
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.23-1.fc20 will be updated
---> Package mysql-community-server.x86_64 0:5.6.24-1.fc20 will be an update
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package                 Arch    Version               Repository          Size
================================================================================
Installing:
 mysql-community-devel   x86_64  5.6.24-1.fc20         mysql56-community  3.4 M
 ruby-devel              x86_64  2.0.0.353-16.fc20     updates            125 k
Updating for dependencies:
 mysql-community-client  x86_64  5.6.24-1.fc20         mysql56-community   19 M
 mysql-community-common  x86_64  5.6.24-1.fc20         mysql56-community  258 k
 mysql-community-libs    x86_64  5.6.24-1.fc20         mysql56-community  2.0 M
 mysql-community-server  x86_64  5.6.24-1.fc20         mysql56-community   55 M
 
Transaction Summary
================================================================================
Install  2 Packages
Upgrade             ( 4 Dependent packages)
 
Total download size: 80 M
Downloading packages:
No Presto metadata available for mysql56-community
(1/6): mysql-community-common-5.6.24-1.fc20.x86_64.rpm      | 258 kB  00:01     
(2/6): mysql-community-devel-5.6.24-1.fc20.x86_64.rpm       | 3.4 MB  00:01     
(3/6): mysql-community-libs-5.6.24-1.fc20.x86_64.rpm        | 2.0 MB  00:00     
(4/6): ruby-devel-2.0.0.353-16.fc20.x86_64.rpm              | 125 kB  00:00     
(5/6): mysql-community-client-5.6.24-1.fc20.x86_64.rpm      |  19 MB  00:09     
(6/6): mysql-community-server-5.6.24-1.fc20.x86_64.rpm      |  55 MB  00:21     
--------------------------------------------------------------------------------
Total                                              3.3 MB/s |  80 MB  00:24     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Updating   : mysql-community-common-5.6.24-1.fc20.x86_64                 1/10 
  Updating   : mysql-community-libs-5.6.24-1.fc20.x86_64                   2/10 
  Updating   : mysql-community-client-5.6.24-1.fc20.x86_64                 3/10 
  Updating   : mysql-community-server-5.6.24-1.fc20.x86_64                 4/10 
  Installing : mysql-community-devel-5.6.24-1.fc20.x86_64                  5/10 
  Installing : ruby-devel-2.0.0.353-16.fc20.x86_64                         6/10 
  Cleanup    : mysql-community-server-5.6.23-1.fc20.x86_64                 7/10 
  Cleanup    : mysql-community-client-5.6.23-1.fc20.x86_64                 8/10 
  Cleanup    : mysql-community-libs-5.6.23-1.fc20.x86_64                   9/10 
  Cleanup    : mysql-community-common-5.6.23-1.fc20.x86_64                10/10 
  Verifying  : mysql-community-client-5.6.24-1.fc20.x86_64                 1/10 
  Verifying  : mysql-community-devel-5.6.24-1.fc20.x86_64                  2/10 
  Verifying  : ruby-devel-2.0.0.353-16.fc20.x86_64                         3/10 
  Verifying  : mysql-community-libs-5.6.24-1.fc20.x86_64                   4/10 
  Verifying  : mysql-community-common-5.6.24-1.fc20.x86_64                 5/10 
  Verifying  : mysql-community-server-5.6.24-1.fc20.x86_64                 6/10 
  Verifying  : mysql-community-client-5.6.23-1.fc20.x86_64                 7/10 
  Verifying  : mysql-community-server-5.6.23-1.fc20.x86_64                 8/10 
  Verifying  : mysql-community-libs-5.6.23-1.fc20.x86_64                   9/10 
  Verifying  : mysql-community-common-5.6.23-1.fc20.x86_64                10/10 
 
Installed:
  mysql-community-devel.x86_64 0:5.6.24-1.fc20                                  
  ruby-devel.x86_64 0:2.0.0.353-16.fc20                                         
 
Dependency Updated:
  mysql-community-client.x86_64 0:5.6.24-1.fc20                                 
  mysql-community-common.x86_64 0:5.6.24-1.fc20                                 
  mysql-community-libs.x86_64 0:5.6.24-1.fc20                                   
  mysql-community-server.x86_64 0:5.6.24-1.fc20                                 
 
Complete!

After installing ruby, exit the root account to your management account and run the following command from the Linux shell:

ruby -v

It should show you:

ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]

Before you can run gem to install rails, you must install another the libxml2-devel library. Here’s the syntax to install the libxml2-devel library:

yum install libxml2-devel

You should see the following, which includes typing a y to continue:

Loaded plugins: langpacks, refresh-packagekit
Resolving Dependencies
--> Running transaction check
---> Package libxml2-devel.x86_64 0:2.9.1-3.fc20 will be installed
--> Processing Dependency: zlib-devel for package: libxml2-devel-2.9.1-3.fc20.x86_64
--> Processing Dependency: xz-devel for package: libxml2-devel-2.9.1-3.fc20.x86_64
--> Running transaction check
---> Package xz-devel.x86_64 0:5.1.2-12alpha.fc20 will be installed
---> Package zlib-devel.x86_64 0:1.2.8-3.fc20 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package             Arch         Version                   Repository     Size
================================================================================
Installing:
 libxml2-devel       x86_64       2.9.1-3.fc20              updates       1.0 M
Installing for dependencies:
 xz-devel            x86_64       5.1.2-12alpha.fc20        updates        45 k
 zlib-devel          x86_64       1.2.8-3.fc20              fedora         50 k
 
Transaction Summary
================================================================================
Install  1 Package (+2 Dependent packages)
 
Total download size: 1.1 M
Installed size: 9.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): xz-devel-5.1.2-12alpha.fc20.x86_64.rpm               |  45 kB  00:00     
(2/3): zlib-devel-1.2.8-3.fc20.x86_64.rpm                   |  50 kB  00:00     
(3/3): libxml2-devel-2.9.1-3.fc20.x86_64.rpm                | 1.0 MB  00:04     
--------------------------------------------------------------------------------
Total                                              264 kB/s | 1.1 MB  00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Installing : zlib-devel-1.2.8-3.fc20.x86_64                               1/3 
  Installing : xz-devel-5.1.2-12alpha.fc20.x86_64                           2/3 
  Installing : libxml2-devel-2.9.1-3.fc20.x86_64                            3/3 
  Verifying  : xz-devel-5.1.2-12alpha.fc20.x86_64                           1/3 
  Verifying  : libxml2-devel-2.9.1-3.fc20.x86_64                            2/3 
  Verifying  : zlib-devel-1.2.8-3.fc20.x86_64                               3/3 
 
Installed:
  libxml2-devel.x86_64 0:2.9.1-3.fc20                                           
 
Dependency Installed:
  xz-devel.x86_64 0:5.1.2-12alpha.fc20     zlib-devel.x86_64 0:1.2.8-3.fc20    
 
Complete!
yum install libxslt-devel

You should see the following and will need to reply with a y during install:

Loaded plugins: langpacks, refresh-packagekit
mysql-connectors-community                                  | 2.5 kB  00:00     
mysql-tools-community                                       | 2.5 kB  00:00     
mysql56-community                                           | 2.5 kB  00:00     
pgdg93                                                      | 3.6 kB  00:00     
updates/20/x86_64/metalink                                  |  14 kB  00:00     
updates                                                     | 4.9 kB  00:00     
updates/20/x86_64/primary_db                                |  13 MB  00:07     
updates/20/x86_64/pkgtags      FAILED                                           
http://mirror.utexas.edu/fedora/linux/updates/20/x86_64/repodata/fe40e35e0289ae1470dbe8030c09b8046924cbaa5e16ac61e9411ac57477820b-pkgtags.sqlite.gz: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
(1/2): updates/20/x86_64/updateinfo                         | 1.9 MB  00:02     
(2/2): updates/20/x86_64/pkgtags                            | 1.4 MB  00:00     
Resolving Dependencies
--> Running transaction check
---> Package libxslt-devel.x86_64 0:1.1.28-5.fc20 will be installed
--> Processing Dependency: libgcrypt-devel for package: libxslt-devel-1.1.28-5.fc20.x86_64
--> Running transaction check
---> Package libgcrypt-devel.x86_64 0:1.5.3-2.fc20 will be installed
--> Processing Dependency: libgpg-error-devel for package: libgcrypt-devel-1.5.3-2.fc20.x86_64
--> Running transaction check
---> Package libgpg-error-devel.x86_64 0:1.12-1.fc20 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package                  Arch         Version               Repository    Size
================================================================================
Installing:
 libxslt-devel            x86_64       1.1.28-5.fc20         fedora       309 k
Installing for dependencies:
 libgcrypt-devel          x86_64       1.5.3-2.fc20          fedora       127 k
 libgpg-error-devel       x86_64       1.12-1.fc20           fedora        16 k
 
Transaction Summary
================================================================================
Install  1 Package (+2 Dependent packages)
 
Total download size: 451 k
Installed size: 2.6 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): libgcrypt-devel-1.5.3-2.fc20.x86_64.rpm              | 127 kB  00:00     
(2/3): libgpg-error-devel-1.12-1.fc20.x86_64.rpm            |  16 kB  00:00     
(3/3): libxslt-devel-1.1.28-5.fc20.x86_64.rpm               | 309 kB  00:00     
--------------------------------------------------------------------------------
Total                                              454 kB/s | 451 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Installing : libgpg-error-devel-1.12-1.fc20.x86_64                        1/3 
  Installing : libgcrypt-devel-1.5.3-2.fc20.x86_64                          2/3 
  Installing : libxslt-devel-1.1.28-5.fc20.x86_64                           3/3 
  Verifying  : libgcrypt-devel-1.5.3-2.fc20.x86_64                          1/3 
  Verifying  : libgpg-error-devel-1.12-1.fc20.x86_64                        2/3 
  Verifying  : libxslt-devel-1.1.28-5.fc20.x86_64                           3/3 
 
Installed:
  libxslt-devel.x86_64 0:1.1.28-5.fc20                                          
 
Dependency Installed:
  libgcrypt-devel.x86_64 0:1.5.3-2.fc20 libgpg-error-devel.x86_64 0:1.12-1.fc20
 
Complete!

One more to go. You can’t run the Ruby gem utility to create the nokogiri Ruby Gem on Fedora because of a library mismatch. If you attempt to create the Rails framework, like this:

gem install rails

It’ll raise the following error message on trying to dynamically link the nokogiri Ruby Gem. The error will be something like this, and unfortunately, the log files won’t be too useful:

Running patch with /usr/local/share/gems/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/usr/local/share/gems/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-redhat-linux-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

The error message isn’t very helpful but the fix is fortunately easy. You install the nokogiri Ruby Gem directly with the yum utility. The following instructs yum to proceed without waiting for you to type a y to install.

yum install -y rubygem-nokogiri
Loaded plugins: langpacks, refresh-packagekit
Resolving Dependencies
--> Running transaction check
---> Package rubygem-nokogiri.x86_64 0:1.6.6.2-1.fc20 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package                Arch         Version                Repository     Size
================================================================================
Installing:
 rubygem-nokogiri       x86_64       1.6.6.2-1.fc20         updates       534 k
 
Transaction Summary
================================================================================
Install  1 Package
 
Total download size: 534 k
Installed size: 834 k
Downloading packages:
rubygem-nokogiri-1.6.6.2-1.fc20.x86_64.rpm                  | 534 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Installing : rubygem-nokogiri-1.6.6.2-1.fc20.x86_64                       1/1 
  Verifying  : rubygem-nokogiri-1.6.6.2-1.fc20.x86_64                       1/1 
 
Installed:
  rubygem-nokogiri.x86_64 0:1.6.6.2-1.fc20                                      
 
Complete!

Now you can use the Ruby gem utility to create the Rails framework like this:

gem install rails

This will take a couple minutes typically, so be patient. You see something like this, dependent on the release:

Fetching: loofah-2.0.1.gem (100%)
Successfully installed loofah-2.0.1
Fetching: rails-html-sanitizer-1.0.2.gem (100%)
Successfully installed rails-html-sanitizer-1.0.2
Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
Successfully installed rails-deprecated_sanitizer-1.0.3
Fetching: rails-dom-testing-1.0.6.gem (100%)
Successfully installed rails-dom-testing-1.0.6
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: erubis-2.7.0.gem (100%)
Successfully installed erubis-2.7.0
Fetching: actionview-4.2.1.gem (100%)
Successfully installed actionview-4.2.1
Fetching: actionpack-4.2.1.gem (100%)
Successfully installed actionpack-4.2.1
Fetching: activemodel-4.2.1.gem (100%)
Successfully installed activemodel-4.2.1
Fetching: arel-6.0.0.gem (100%)
Successfully installed arel-6.0.0
Fetching: activerecord-4.2.1.gem (100%)
Successfully installed activerecord-4.2.1
Fetching: globalid-0.3.5.gem (100%)
Successfully installed globalid-0.3.5
Fetching: activejob-4.2.1.gem (100%)
Successfully installed activejob-4.2.1
Fetching: mime-types-2.4.3.gem (100%)
Successfully installed mime-types-2.4.3
Fetching: mail-2.6.3.gem (100%)
Successfully installed mail-2.6.3
Fetching: actionmailer-4.2.1.gem (100%)
Successfully installed actionmailer-4.2.1
Fetching: rake-10.4.2.gem (100%)
Successfully installed rake-10.4.2
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: railties-4.2.1.gem (100%)
Successfully installed railties-4.2.1
Fetching: bundler-1.9.2.gem (100%)
Successfully installed bundler-1.9.2
Fetching: hike-1.2.3.gem (100%)
Successfully installed hike-1.2.3
Fetching: multi_json-1.11.0.gem (100%)
Successfully installed multi_json-1.11.0
Fetching: tilt-1.4.1.gem (100%)
Successfully installed tilt-1.4.1
Fetching: sprockets-2.12.3.gem (100%)
Successfully installed sprockets-2.12.3
Fetching: sprockets-rails-2.2.4.gem (100%)
Successfully installed sprockets-rails-2.2.4
Fetching: rails-4.2.1.gem (100%)
Successfully installed rails-4.2.1
Parsing documentation for actionmailer-4.2.1
Installing ri documentation for actionmailer-4.2.1
Parsing documentation for actionpack-4.2.1
Installing ri documentation for actionpack-4.2.1
Parsing documentation for actionview-4.2.1
Installing ri documentation for actionview-4.2.1
Parsing documentation for activejob-4.2.1
Installing ri documentation for activejob-4.2.1
Parsing documentation for activemodel-4.2.1
Installing ri documentation for activemodel-4.2.1
Parsing documentation for activerecord-4.2.1
Installing ri documentation for activerecord-4.2.1
Parsing documentation for arel-6.0.0
Installing ri documentation for arel-6.0.0
Parsing documentation for builder-3.2.2
Installing ri documentation for builder-3.2.2
Parsing documentation for bundler-1.9.2
Installing ri documentation for bundler-1.9.2
Parsing documentation for erubis-2.7.0
Installing ri documentation for erubis-2.7.0
Parsing documentation for globalid-0.3.5
Installing ri documentation for globalid-0.3.5
Parsing documentation for hike-1.2.3
Installing ri documentation for hike-1.2.3
Parsing documentation for loofah-2.0.1
Installing ri documentation for loofah-2.0.1
Parsing documentation for mail-2.6.3
Installing ri documentation for mail-2.6.3
Parsing documentation for mime-types-2.4.3
Installing ri documentation for mime-types-2.4.3
Parsing documentation for multi_json-1.11.0
Installing ri documentation for multi_json-1.11.0
Parsing documentation for rails-4.2.1
Installing ri documentation for rails-4.2.1
Parsing documentation for rails-deprecated_sanitizer-1.0.3
Installing ri documentation for rails-deprecated_sanitizer-1.0.3
Parsing documentation for rails-dom-testing-1.0.6
Installing ri documentation for rails-dom-testing-1.0.6
Parsing documentation for rails-html-sanitizer-1.0.2
Installing ri documentation for rails-html-sanitizer-1.0.2
Parsing documentation for railties-4.2.1
Installing ri documentation for railties-4.2.1
Parsing documentation for rake-10.4.2
Installing ri documentation for rake-10.4.2
Parsing documentation for sprockets-2.12.3
Installing ri documentation for sprockets-2.12.3
Parsing documentation for sprockets-rails-2.2.4
Installing ri documentation for sprockets-rails-2.2.4
Parsing documentation for thor-0.19.1
Installing ri documentation for thor-0.19.1
Parsing documentation for tilt-1.4.1
Installing ri documentation for tilt-1.4.1
Done installing documentation for actionmailer, actionpack, actionview, activejob, activemodel, activerecord, arel, builder, bundler, erubis, globalid, hike, loofah, mail, mime-types, multi_json, rails, rails-deprecated_sanitizer, rails-dom-testing, rails-html-sanitizer, railties, rake, sprockets, sprockets-rails, thor, tilt after 475 seconds
26 gems installed

If you want to install Phusion Passenger, mod_passenger is already installed. You should note that support and testing for this stops at Fedora V17. You can verify installation with the following command:

yum list mod_passenger

It returns:

Loaded plugins: langpacks, refresh-packagekit
Available Packages
mod_passenger.x86_64                   4.0.53-3.fc20.2                   updates

You can also install the Ruby Gem for Passenger, like this:

gem install passenger

It should take less than 2 minutes and return something like this:

Fetching: passenger-5.0.6.gem (100%)
Building native extensions.  This could take a while...
Successfully installed passenger-5.0.6
Parsing documentation for passenger-5.0.6
Installing ri documentation for passenger-5.0.6
Done installing documentation for passenger after 9 seconds
1 gem installed

As always, I hope this was helpful. I’ll add a post with the remaining MySQL and Oracle connection details soon.

Written by maclochlainn

April 10th, 2015 at 2:28 am

APEX Create Table

with 2 comments

The following walks you through how you sign on to a STUDENT Workspace with Oracle’s APEX product. It shows you how to create a new table with the Object Browser tool.

You can find instructions on how to create your own STUDENT Workspace in this blog post. Overall, Oracle APEX is a valuable tool to learn and master.

UseStudentAPEX01

  1. You start the process by accessing the Oracle Database 11g APEX, which you can access at http://localhost:8080/apex by default on the server. If you’ve got a static IP address for your instance, you can replace localhost with the IP address or hostname for the IP address.

    • Workspace: STUDENT
    • Username:  ADMIN
    • Password:  STUDENT

UseStudentAPEX02

  1. After you login to the STUDENT workspace, you have four options. They are the: Application Builder, SQL Workshop, Team Development, and Administration. You start the process by accessing the Oracle Database 11g APEX, which you can access at http://localhost:8080/apex by default on the server. If you’ve got a static IP address for your instance, you can replace localhost with the IP address or hostname for the IP address. Click on the Object Browser icon to proceed.

UseStudentAPEX02A

  1. Clicking the SQL Workshop icon takes you to the second level menu. You click the Object Browser icon to create a database object.

OracleAPEXCT01

  1. After clicking the Object Browser icon, you see the screen at the left. Click the Create button to create a table.

OracleAPEXCT02

  1. After clicking the Create button, you see the screen at the left. Click the type of database object that you want to create. In our case, we click the Table hypertext to start the create table workflow.

OracleAPEXCT03

  1. After clicking the Table hyperlink, you see the Create Table screen at the left. Enter the column names, choose their data types and set the scale and precision. You should also check the Not Null checkbox when you want a column to be mandatory. Click the Next button to continue the create table workflow.

OracleAPEXCT04

  1. After entering the column names, you should choose the data types, enter the scale and precision, and check the NOT NULL checkbox to make appropriate columns mandatory by applying NOT NULL database constraints. If you run out of entry rows, you can click the Add Column button to add new rows. Click the Next button to continue the create table workflow when you’ve defined the columns.

OracleAPEXCT05

  1. After defining the column names, you should choose whether the primary key will use a new sequence or an existing sequence. You also have the ability to not assign a primary key value or simply leave it unpopulated when inserting new rows. The example creates an IMAGE_PK primary key constraint on the IMAGE_ID column, and declares an IMAGE_SEQ sequence value. Click the Next button to continue the create table workflow when you’ve defined the primary key constraint and any new sequence value for the primary key column.

OracleAPEXCTFK1

  1. After defining the primary key constraint, you can define foreign key column constraints. You enter a foreign key constraint name, choose between a Disallow Delete, Cascade Delete, or Set Null on Delete rule, select the foreign key column, the foreign key’s referenced table and column. Click the Add button to continue the create table workflow.

OracleAPEXCTFK2

  1. After defining a foreign key constraint, you can see the constraint that you created. Then, you can define another foreign key column constraints. You repeat the steps from the prior steps to add another foreign key constraint. Click the Add button to create a second foreign key constraint and complete the create table workflow.

OracleAPEXCTFK3

  1. After defining a second foreign key constraint, you see the following two foreign key constraints. Click the Next button to complete the create table workflow.

OracleAPEXTCUK01

  1. After defining all the foreign key constraints, you can create check and unique constraints. You check a radio button for a check or unique constraint, and then you select the columns for the constraint’s key. Click the /Add button to create any check or unique constraints as part of the create table workflow.

OracleAPEXTCUK02

  1. After defining all check and unique key constraints, you can see them in the Constraints box. Click the Next button to complete the create table workflow.

OracleAPEXCTC01

  1. After defining all items about the table, you can see the SQL to create the IMAGE table and its constraints. You can copy the SQL into a file for later use when writing a re-runnable script. Click the Create button to complete the create table workflow and create the table.

     

    The following are the contents of the script for the actions you’ve defined:

    CREATE table "IMAGE" (
        "IMAGE_ID"         NUMBER NOT NULL,
        "FILE_NAME"        VARCHAR2(60) NOT NULL,
        "MIME_TYPE"        NUMBER NOT NULL,
        "ITEM_IMAGE"       BLOB,
        "CREATED_BY"       NUMBER NOT NULL,
        "CREATION_DATE"    DATE NOT NULL,
        "LAST_UPDATED_BY"  NUMBER NOT NULL,
        "LAST_UPDATE_DATE" DATE NOT NULL,
        constraint  "IMAGE_PK" primary key ("IMAGE_ID")
    )
    /
    
    CREATE sequence "IMAGE_SEQ" 
    /
    
    CREATE trigger "BI_IMAGE"  
      before insert on "IMAGE"              
      for each row 
    begin  
      if :NEW."IMAGE_ID" is null then
        select "IMAGE_SEQ".nextval into :NEW."IMAGE_ID" from dual;
      end if;
    end;
    /   
    
    ALTER TABLE "IMAGE" ADD CONSTRAINT "IMAGE_FK1" 
    FOREIGN KEY ("CREATED_BY")
    REFERENCES "SYSTEM_USER" ("SYSTEM_USER_ID")
    
    /
    ALTER TABLE "IMAGE" ADD CONSTRAINT "IMAGE_FK2" 
    FOREIGN KEY ("LAST_UPDATED_BY")
    REFERENCES "SYSTEM_USER" ("SYSTEM_USER_ID")
    
    /
    alter table "IMAGE" add
    constraint "IMAGE_UK1" 
    unique ("FILE_NAME","MIME_TYPE")
    /   
    

OracleAPEXTable

  1. After creating the table, trigger, sequence, and constraints, you can see the table definition. You also have the ability to modify the table. At this point, you can create another structure or you can click the Home or SQL Workshop menu choice.

As always, I hope this helps those looking to learn new things and approaches.

Written by maclochlainn

April 7th, 2015 at 10:21 pm

APEX SQL Query

without comments

The following walks through how you sign on to a STUDENT Workspace with Oracle’s APEX product and write and run free-form SQL statements. You can find instructions on how to create your own STUDENT Workspace.

While this blog introduces several concepts and features of Oracle APEX, it only focuses on how to write and run free-form SQL statements. Overall, Oracle APEX is a valuable tool to learn and master.

UseStudentAPEX01

  1. You start the process by accessing the Oracle Database 11g APEX, which you can access at http://localhost:8080/apex by default on the server. If you’ve got a static IP address for your instance, you can replace localhost with the IP address or hostname for the IP address.

    • Workspace: STUDENT
    • Username:  ADMIN
    • Password:  STUDENT

UseStudentAPEX02

  1. After you login to the STUDENT workspace, you have four options. They are the: Application Builder, SQL Workshop, Team Development, and Administration. You start the process by accessing the Oracle Database 11g APEX, which you can access at http://localhost:8080/apex by default on the server. If you’ve got a static IP address for your instance, you can replace localhost with the IP address or hostname for the IP address. Click on the SQL Workshop icon to proceed.

    • Application Builder: Let’s you build custom APEX applications.
    • SQL Workshop: Let’s you work with custom SQL, and APEX provides you with the following utilities:
      • Object Browser: Lets you create tables, views, and other objects.
      • SQL Commands: Lets you run individual SQL statements inside a browser window and returns results in the bottom pane.
      • SQL Scripts: Lets you create, upload, delete, and run scripts from the browser.
      • Query Builder: Lets you create free form queries that include joins between tables, but limits you to primary to foreign key table relationships. That means you can’t write range joins with a cross join and the BETWEEN operator and you can’t write self-joins.
      • Utilities: Lets you work with the Data Workshop (imports and exports data), Object Reports (a SQL report writer tool), Generate DDL (a tool that creates structures in the database), User Interface Defaults (coordinate data dictionary), Schema Comparison (a tool to compare similarities between schemas, About Database (the ability to connect as the database administrator), and Recycle Bin (dropped and purged structures).
    • Team Development: A project management tool.
    • Administration: Lets you manage database services, users and groups, monitor activities, and dashboards. You should note that the SQL query doesn’t have a semicolon like it would in a SQL*Plus environment. The Run button acts as the execution operator and effectively replaces the role of the semicolon, which traditionally executes a statement.

UseStudentAPEX02A

  1. Clicking the SQL Workshop icon takes you to the second level menu. You click the SQL Commands icon to enter a free-form SQL statement. Click on the SQL Commands icon to proceed.

UseStudentAPEX03

  1. The first text panel lets you enter free-form queries. The Autocommit checkbox is enabled, which means the result of INSERT and UPDATE statements are immediate and don’t require a COMMIT statement. The second text panel displays results from a query or acknowledgment of statement completion.

UseStudentAPEX04

  1. This screen shot shows a query in the first panel and the results of the query in the second panel.

As always, I hope this helps those looking to learn new things and approaches.

Written by maclochlainn

April 5th, 2015 at 4:36 pm

APEX Create Workspace

with 2 comments

In a prior post, I showed you how to access Oracle Database 11g XE APEX. This post shows you how to create a basic workspace against a student database (or, what Oracle lables a schema, which is synonymous with a database).

Oracle11gAPEX_01

  1. You start the process by accessing the Oracle Database 11g APEX, which you can access at http://localhost:8080/apex by default on the server. If you’ve got a static IP address for your instance, you can replace localhost with the IP address or hostname for the IP address.

    • Workspace: INTERNAL
    • Username:  ADMIN
    • Password:  installation_system_password

Oracle11gAPEX_02

  1. After logging into the Oracle Application Express (APEX) system, you see the Home page at the left. Click the Manage Workspace button on the Home page.

Oracle11gAPEX_03

  1. Manage Workspace Dialog: After clicking the Manage Workspace button on the Home page, you see four major options to manage workspaces. They are the Workspace Actions, Workspace Reports, Export Import, and Manage Applications. You want to click on the Create Workspace to create a new workspace.

Oracle11gAPEX_03A

  1. Identify Workspace Diaglog: Enter a Workspace Name and Workspace Description. Then, click on the Next button move forward in the workflow.

Oracle11gAPEX_04

  1. Create Workspace Dialog: You create a workspace, APEX presumes you want to create a new schema. That’s why the Re-use existing schema drop down chooses No by default. You enter the Schema Name as STUDENT, the Password for the STUDENT schema, and an initial Space Quota (MB) of 100. Then, click the Next button to continue.

Oracle11gAPEX_05

  1. Identify Schema Dialog: If the schema you chose exists, you get the correction dialog. You need to change the Re-use existing schema drop down from No to Yes. Then, click the Next button to continue.

Oracle11gAPEX_06

  1. Identify Administrator Dialog: Here you enter an Administrator Username, Password, First Name, Last Name, and email address. Then, click the Next button to continue.

Oracle11gAPEX_07

  1. Confirm Request Dialog: Here you review your entries and click the Confirm Request button to continue.

Oracle11gAPEX_08

  1. Success Confirmation Dialog: Here you click the Done Request button to continue.

As always, I hope this helps you learn how to create a workspace.

Written by maclochlainn

April 5th, 2015 at 1:38 am

Oracle 11g XE APEX

with 3 comments

The question for most new Oracle users is what’s Apex? They have a different question When they discover how to connect to the Oracle Database 11g XE default instance with this URL:

http://localhost:8080/apex

You’ll see the following web site, and wonder what do I enter for the Workspace, the Username, and the Password values?

Apex01

The answers are:

  • Default Workspace: INTERNAL
  • Default User: ADMIN
  • Default Password: SYS or SYSTEM Password from Install

Enter those values within the initial password time interval and you’ll arrive at the next screen where you can manage the Oracle Database 11g XE instance. If you wait too long, you’ll be redirected to enter the original SYS or SYSTEM password from install and a new password twice. The rules for a new password are:

  • Password must contain at least 6 characters.
  • New password must differ from old password by at least 2 characters.
  • Password must contain at least one numeric character (0123456789).
  • Password must contain at least one punctuation character (!”#$%&()“*+,-/:;<=>?_).
  • Password must contain at least one upper-case alphabetic character.
  • Password must not contain username.

Whether you go directly to the next screen or have to enter your a new password, you should see the following screen:

Apex02

You can find the default configuration for the installation with the following anonymous PL/SQL block:

DECLARE
  /* Declare variables. */
  lv_endpoint    NUMBER := 1;
  lv_host        VARCHAR2(80);
  lv_port        NUMBER;
  lv_protocol    NUMBER;
BEGIN
  /* Check for current XDB settings. */
  dbms_xdb.getlistenerendpoint( lv_endpoint
                              , lv_host
                              , lv_port
                              , lv_protocol );
 
  /* Print the values. */
  dbms_output.put_line('Endpoint: ['||lv_endpoint||']'||CHR(10)||
                       'Host:     ['||lv_host||']'||CHR(10)||
                       'Port:     ['||lv_port||']'||CHR(10)||
                       'Protocol: ['||lv_protocol||']');
END;
/

It should print the following:

Endpoint: [1]
Host:	  [localhost]
Port:	  [8080]
Protocol: [1]

This is a standalone configuration and you can’t connect to the XDB server from another machine. You can only connect from the local machine.

I hope this helps those trying to use the default Apex 4 installation provided as part of the Oracle Database 11g XE instance. You can read an older post of mine that shows you how to set up a basic Workspace, but after reflection I’ll write more about creating and managing workspaces.

Written by maclochlainn

April 2nd, 2015 at 1:18 am