Wednesday, April 14, 2010

Using rsync for backups

Previous: Renaming FAT32 and NTFS filesystems

Being a n00b and all, it's probably no surprise to you that I've been backing up my files by dragging and dropping folder icons in Nautilus. Knowing that, it's probably no surprise that these backup operations might take hours to complete. I used to start a backup operation before going to bed, and leave it running while I slept.

I had n00bishly assumed that when gnome asked me if I wanted to merge files with matching names, it would only copy those files that were different than the version on the target. After all, that would be the logical thing to do, wouldn't it? No such luck.

Then I discovered a very useful file syncing utility, rsync. It's already installed on Ubuntu as shipped. It's nothing new, but it's new to me. It only copies files that have changed.

I found I could back up any of my top-level directory trees to an external drive quickly. For example, this command backs up my /usr directory, which is the mount point of a partition on the internal hard drive:
sudo rsync -av /usr /media/1TB_HDD_external/
The first time, when there was nothing at the destination location, rsync took about 15 minutes to back up a partition of 320GB+. Subsequently, it ran in just a couple of minutes. Very convenient!

It was easy to script this so that everyday backups are easy to run. For instance, this
backup personal
will run
sudo rsync -av /home/dave/Personal /media/1TB_HDD_external


Next: Installing Oracle Express and ADF - FAIL!

Renaming FAT32 and NTFS filesystems

Previous: Installing Gwibber

I wanted to rename my Western Digital My Book volumes, because they are all named "My Book." It would be too easy to make a mistake and format the wrong volume or restore from the wrong backup. From community help at https://help.ubuntu.com/community/RenameUSBDrive, I learned that gparted can rename an NTFS filesystem without reformatting it.

To install gparted, I opened a Terminal and ran
sudo apt-get install gparted
sudo apt-get install mtools
sudo apt-get install ntfsprogs
Gparted is the partition management utility, mtools is a package of utilities for working with FAT filesystems, and ntfsprogs is a package of utilities for working with NTFS filesystems.

Running gparted as root (that is, sudo gparted), I saw the partitions on my internal drive but none of the external drives. There's a Devices drop-down in the GParted menu, and there I found three devices /dev/sda, sdb, and sdc. I identified the volume I wanted to rename, right-clicked on it and chose unmount. This ran for a long, long time. I checked using Nautilus and the drive was not mounted. I cancelled gparted and started it up again, to see if it would let me try the rename operation. It just kept searching and searching and searching for partitions on /dev/sbc.

I disconnected the external drive, killed gparted, and started it again. This time it immediately displayed the list of partitions on the internal drive. I shut down gparted, then reconnected the external drive. After it automounted, I unmounted it using Nautilus, but left it physically connected. Once again, gparted just looped, ostensibly searching for partitions on the device.

A FAT32 filesystem



So, gparted did not work. I tried the command-line approach outlined on the community help page cited above. I connected the external drive and waited for it to automount. Then I ran
mount
to see the mounted filesystems and found where the external drive was mounted. In this case, it was /dev/sdc1. I unmounted it with
sudo umount /dev/sdc1
Then I verified it was the volume I wanted with
sudo mlabel -i /dev/sdc1 -s ::
Finally, I changed the volume label with
sudo mlabel -i /dev/sdc1 ::500GB_FAT32_external
I mounted the volume and it worked fine.

An NTFS filesystem



Followed a similar procedure to relabel an NTFS volume. Connected it, waited for it to automount, and unmounted it with
sudo umount /dev/sdb1
Checked the current label with
sudo ntfslabel /dev/sdb1
Changed the label with
sudo ntfslabel /dev/sdb1 1TB_NTFS_external
Checked to be sure I had changed the label correctly, then re-mounted the volume. Worked great!

Next: Using rsync for backups

Tuesday, April 13, 2010

Installing Gwibber

Previous: Installing a gmail notifier

Ran the command
sudo apt-get install gwibber
Gwibber then appeared under Applications > Internet > Gwibber Microblogging Client. Defining the Twitter account was easy. Defining the Facebook account was confusing. Not sure if it worked.

The program appears to work fairly well and looks good. It locks up if I use the scroll wheel on the mouse too rapidly. It's not limited to Twitter, but when using Twitter it doesn't seem to be as functional as the basic Web interface. I will try it for a while and see how it goes.

Next: Renaming FAT32 and NTFS filesystems

Installing a gmail notifier

Previous: Upgrading Eclipse after reinstalling Ubuntu

Followed instructions at Ubuntu Geek to install CheckGmail, a Gmail notifier for Ubuntu.

Ran the command
sudo apt-get install checkgmail
Instead of pressing ALT+F2, I just typed checkgmail in Terminal. It started the program. I entered my Gmail account information, changed the External Command to
firefox-3.5 %u
and left all other defaults unchanged. The program was unable to log into Gmail. It complained that the userid or password was incorrect. After checking to be sure I had entered the correct values, I decided the program simply does not work, and I removed it with
sudo apt-get remove checkgmail


Next, I tried gm-notify from Launchpad. Downloaded the tarball, unpacked it, and read the README for installation instructions. It's a Python app and has some dependencies, duly noted in the README. Per the instructions, I ran
sudo apt-get install python-indicate python-notify python-gst0.10 python-gtk2 python-gconf python-twisted-mail
to install the prereqs, then from the top-level directory of the extracted files, ran
sudo ./setup.py install
The README says the application will appear in the menu Applications > Network > GMail Notifier, but in fact it appeared in Applications > Internet > GMail Notifier. Furthermore, the README says the configuration app will appear under System > Settings > GMail Notifier Configuration, but in fact it appeared in System > Preferences > GMail Notifier Configuration.

Sent myself an email to see what the application would do. Works well, is simple, looks good. I'll keep this one.

Next: Installing Gwibber

Upgrading Eclipse after reinstalling Ubuntu

Previous: Reinstalling some favorite apps after reinstalling Ubuntu

Ubuntu repositories have Eclipse 3.2. I wanted a more recent version. I went to http://www.eclipse.org and downloaded the basic JEE packaging of Eclipse Galileo as a tarball.

Deleted the old ~/.eclipse directory. Unpacked the tarball into /home and changed the name of the top-level directory to ~/.eclipse. Changed /usr/share/applications/eclipse.desktop to point to the executable. Works fine.

Next: Installing a gmail notifier

Shell personalization after reinstalling Ubuntu

Previous: Reinstalling some favorite apps after reinstalling Ubuntu

Shell personalization after reinstalling Ubuntu



I set up some preferences in login files a little differently than before, based on tips from Stefaan Lippens. I put environment variable definitions in .profile and sourced .profile and .bash_aliases in .bash_profile. This seems to be quite a convenient setup. Added the following to .bash_aliases
# Shortcuts for directory listings
alias ll='ls -lF --color=auto'
alias la='ls -alF --color=auto'
alias ls='ls -F'

# Highlight matches in grep
alias grep='grep --color=auto'

# Start and stop my local wiki
alias wiki='~/.bin/wiki'
alias wiki_stop='~/.bin/wiki_stop'

# Start Freemind mind-mapping tool
alias freemind='~/.freemind/freemind.sh'

# Start UMLet diagramming tool
alias umlet='umlet.sh'
Uncommented the following lines in the provided .bashrc
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi


Next: Upgrading Eclipse after reinstalling Ubuntu

Reinstalling some favorite apps after reinstalling Ubuntu

Previous: Restoring Firefox personalization after re-installing Ubuntu

So, I wanted to reinstall some of the apps I had been using before. But the way I had them scattered around the filesystem was pretty sloppy. Better this time.

Recovering my local wiki



Installed sqlite3 and sqlite ruby support (Instiki depends on them):
sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby
Put the wiki under /home/.wiki so that it would not show up in normal directory listings.

Moved the wiki icon to /usr/share/pixmaps to make it consistent with other applications.

Put a wiki icon on the top panel for convenient starting.

For more information about how I've customized Instiki for personal use, see http://kotowanandesu.blogspot.com/2009/08/pimp-my-instiki.html.

Reinstalling Google Earth



Installed Google Earth by following the instructions I documented on this blog at http://kotowanandesu.blogspot.com/2009/09/google-earth-install.html. I downloaded a fresh copy in case there have been any updates since the last time I installed it.

Had a problem this time that I didn't have last time. The installer complained that gtk2 was missing.

Searching for similar problems, I found that some people had installed lib32nss-mdns, and this solved the problem for them. I tried
sudo apt-get install lib32nss-mdns
and ran the installer again.

The console output was:
setup.data/bin/Linux/amd64/setup.gtk2: error while loading
shared libraries: libxml2.so.2: cannot open shared
object file: No such file or directory
setup.data/bin/Linux/amd64/setup.gtk: error while loading
shared libraries: libSM.so.6: cannot open shared
object file: No such file or directory
The setup program seems to have failed on amd64
Better, but apparently I forgot to install libxml2 after reinstalling Ubuntu. I found a security notice for 9.04 at http://www.ubuntu.com/usn/USN-815-1 advising an upgrade. I did that and tried
sudo apt-get install libxml2
and it informed me the latest version of libxml2 was already installed. So, that wasn't the problem.

There are many personal blogs out there written by people whose installation worked properly on the first try. I found no help that addresses the problems I'm seeing today.

I ran across a comment by Daniel Holbach buried in a long list of comments on one article that advised the following:
$ sudo apt-get install googleearth-package
$ make-googleearth-package --force
Doubleclick on the resulting .deb file.
I gave that a try, since there was little to lose at this point.

The make spewed hundreds of warning-level messages. The installer proved to be a very long-running process. I left it running during the day and checked on it after work. It worked fine.

This time I put the app in ~/.googleearth so that it would not show up in normal directory listings.

Reinstalling Freemind



Copied my old installation of Freemind from a backup. Referred to to set it up. This time, I put the app in ~/.freemind and set an alias for 'freemind' instead of putting the absolute path in the freemind.desktop file. No problems with this install.

Reinstalling UMLet



A new version of UMLet is available. I downloaded the standalone version and the Eclipse plugin from http://www.umlet.com, version 10.1. I had 10.0 previously. Recovering from a system crash offers all sorts of opportunities for improvement.

I set up the standalone version in the same way as I had set up Freemind. This time, I noticed that UMLet has its own logo. I downloaded the logo from their site and associated it with the app, instead of the icon I came up with before.

Installation of the standalone UMLet consists of unpacking the zip file. The shell script that starts the program already had execute privileges. Convenient. The default directory name is UMLet. I changed it to .umlet. I defined an alias, umlet, in .bash_aliases, ran my .bash_profile and gave it a try.

Didn't work. I took a look at the UMLet.sh file, and learned that it looks for an environment variable, UMLET_HOME. So, they've made things a bit more formal. I added these lines to my .profile:
UMLET_HOME=~/.umlet
export UMLET_HOME
then copied ~/.umlet/UMLet.sh to ~/.bin/umlet.sh and uncommented the line that changes to the UMLET_HOME directory. Typing umlet at a command prompt started the program properly.

I copied the umlet.desktop file from my backup and changed it to refer to the new logo file:
[Desktop Entry]
Encoding=UTF-8
Name=UMLet
Comment=UML diagramming tool
Exec=umlet
Icon=umlet_logo.jpg
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true
and copied the logo file to /usr/share/pixmaps. At this point, UMLet appeared in the gnome menu under Applications > Programming, but the logo image was not displayed. I used Gimp to change it from .jpg to .png. Worked!

Logged out and in and tried to run UMLet from the menu. The launcher was unable to start the child process. It complained that there was no such file or directory as "umlet." I checked .bash_aliases and it looked correct. There must be something about launchers I don't quite understand. I changed the alias to give the absolute path of umlet.sh, logged out and in, and tried again. Worked!

Dropped the jar for the UMLet Eclipse plugin into the Eclipse plugin directory and started Eclipse. Created a UML diagram from Eclipse's New... dialog. Looks good.

Reinstalling Banshee



Ran the command
sudo apt-get install banshee
Banshee appeared in the gnome menu, and started normally. It imported my music files correctly. It played mp3 files correctly. It imported my video files correctly. It played .flv, .mov, .mp4, .mpg, .mpeg correctly.

Next: Shell personalization after reinstalling Ubuntu

Sunday, April 11, 2010

Restoring Firefox personalization after re-installing Ubuntu

Previous: Installing .NET development support

1. Version update

sudo apt-get update
sudo apt-get install firefox-3.5

Then edited the Properties for the Firefox launcher in the Applications menu to invoke firefox-3.5 instead of firefox.

Fortunately, the Ubuntu Modifications for Firefox aren't compatible with this version, so there was no need to disable them manually.

2. Plugins

Went to http://get.adobe.com/flashplayer to try and install Flash Player. (I've had problems with this in the past. Expectations are low.) Selected the .deb file option from the dropdown list. The installer complained about "wrong architecture." FAIL.

A search for "install flash 64-bit linux" found http://labs.adobe.com/downloads/flashplayer10_64bit.html, with instructions to download a tarball of a beta 64-bit version of Flash Player 10. Adobe provides no help about what to do with the tarball's contents. I found several threads about problems with multimedia on Ubuntu, and surmised that plugins might belong in /usr/lib/mozilla/plugins. I unpacked the tarball and copied libflashplayer.so to that location, then restarted Firefox. Youtube videos then played normally.

3. Preferences

In Firefox, I went to Edit > Preferences.

* On the Main tab, under Startup, for the When Firefox starts dropdown, I selected "Show a blank page."

* On the Main tab, under Downloads, I left the default setting of "Desktop" for Save files to. Previously, I had a downloads directory under /home. Now I think that was only an invitation to be lazy. If downloaded file icons appear on my desktop, it's an incentive to put them where they really belong or delete them.

* On the Main tab, under Location Bar, set "...suggest" to "Bookmarks". When I had it set to "History and Bookmarks" it tended to be too cluttered to be useful after several hours online. This way, I can whitelist useful sites by adding them to my bookmarks.

* On the Privacy tab, under History, I deselected "Keep my history..." and "Remember what I enter..." and left "Remember what I've downloaded" selected. I don't use the history to find sites I've visited before. To me, the other options are more distracting than useful. I like simplicity.

* On the Privacy tab, under Private Data, I selected "Always clear...when I close..." and deselected "Ask me..." In Settings I left the default selections.

* On the Security tab, under Passwords, I deselected "Remember passwords for sites." This is a laptop, and there is a risk of identity theft or other problems if people can discover passwords easily. Besides, if I have to enter passwords every time, I'm less likely to forget them.

* On the Advanced tab, under Browsing, I deselected "Check my spelling as I type." Another distraction of dubious value.

* On the Tabs tab, selected "When I open a link in a new tab, switch to it immediately". Why else would I open a link, besides wanting to read it? What were they thinking when they defined this default?

4. Add-ons

* From http://www.xmarks.com installed the XMarks plugin. When you complete the installation, it walks you through a series of dialogs to help you get set up. I logged in with my XMarks account and told it to "Keep data on the server; discard data on this computer." This was the first time I had used the service in this way. It worked perfectly.

* From http://readitlaterlist.com/firefox/, installed Read It Later. It did not recognize the Read It Later folder in Bookmarks, and thought I had no entries. After searching for help on that without success, I decided there was no need to keep those bookmarks anyway. I had marked them to read later, but had never bothered to do so. They must not have been important after all.

I didn't bother with all the add-ons for development and testing, email notification, and so forth. I'll add them as I find I need them. I think I got carried away with add-ons last time around. Clean start this time.

Next: Reinstalling some favorite apps after reinstalling Ubuntu

Installing .NET development support

Previous: Installing Tomcat (partial FAIL)

I'm not actively working on a mono project at the moment, so I didn't spend too much time configuring a development environment. Actually, I didn't spend any time configuring a development environment. I installed the basic tools with these commands:

sudo apt-get install
mono-devel
libmono-winforms2.0-cil
monodevelop
monodevelop-nunit
monodevelop-debugger-mdb

If you're interested, my notes about getting started with these tools are in this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-net.html.

Next: Restoring Firefox personalization after re-installing Ubuntu

Installing Tomcat (partial FAIL)

Previous: Installing Java support

The last time I installed Tomcat on Ubuntu 9.04, the documented easy installation method didn't work and I resorted to installing from a tarball. Since I'm installing 9.04 again rather than a later release, there's no reason to expect different behavior from the installer today.

This time, I want to run Tomcat from a hidden directory under /home so that the everyday view of /home won't be cluttered with various development tools, as before. I decided to go with Tomcat 5.5 for the moment.

I wanted to be able to run customized Tomcat instances for particular development projects on localhost. To that end, I configured a vanilla instance to use as a template to copy into different projects as needed.

This is what I did:

Install Tomcat Core



1. Went to http://tomcat.apache.org/ and download the following distros:

* Core
* Deployer (did not install this)
* Administration Web Application (did not install this)

2. Under /home/.bin I created a directory for local Tomcat instances, tomcat. So I had /home/.bin/tomcat.

3. Moved the Core tarball to /home/.bin/tomcat and unpacked it in place using

tar xzfv *

This resulted in a directory containing the Tomcat core at /home/.bin/tomcat/apache-tomcat-5.5.28.

4. Deleted the tarball apache-tomcat-5.5.28.tar.gz.

5. Granted execute permission on everything in Tomcat's bin directory

cd /home/.bin/tomcat/apache-tomcat-5.5.28/bin
chmod +x *


6. Edited [TOMCAT-HOME]/conf/tomcat-users.xml and changed the default entries

<tomcat-users>
<user name="tomcat" password="tomcat" roles="tomcat" />
<user name="role1" password="tomcat" roles="role1" />
<user name="both" password="tomcat" roles="tomcat,role1" />
</tomcat-users>

to

<tomcat-users>
<user name="tomcat" password="tomcat" roles="tomcat" />
<user name="admin" password="admin" roles="tomcat,manager" />
</tomcat-users>


7. Set the JAVA_HOME environment variable. To find out the value to set, I looked in /etc/alternatives for the java link and found /usr/lib/jvm/java-6-sun/jre/bin/java. So, the value for JAVA_HOME should be /usr/lib/jvm/java-6-sun/jre. Edited /etc/environment and added the line:

JAVA_HOME="/usr/lib/jvm/java-6-sun/jre"


8. Gave Tomcat a trial run:

cd [TOMCAT-HOME]/bin
startup.sh

Exceptions were thrown complaining that native libraries recommended for good performance in a production environment were not found. This is not relevant to my localhost dev environment.

Opened a browser and went to localhost:8080. Tomcat was up and running. The Manager application worked with the userid and password I had set in tomcat-users for the admin role.

Install Administration Web Application — FAIL



1. Unpacked the Administration Web Application tarball to a temporary location.

2. Copied directory server/webapps/admin to [TOMCAT-HOME]/server/webapps.

3. Copied conf/Catalina/localhost/admin.xml to [TOMCAT-HOME]/conf/Catalina/localhost.

4. Restarted Tomcat.

Tomcat restarted normally. Going to http://localhost:8080/admin just resulted in the default message that the Administration app is not shipped by default anymore. Going to Manager, I could see the admin application deployed but not active. Choosing start resulted in an unhelpful message telling me that the app could not be started.

I found a number of threads online where people had reported the same problem. There were several workarounds, and I tried a couple. Apparently this problem occurs sometimes, but not always, and people are able to work around it by uninstalling and reinstalling, possibly five or six times, but this does not always fix the problem. In my case, it made no difference.

My personal view is that tools should not get in our way. The truth is I don't need the Administration app for local development. I don't really need the Deployer, either, so I blew off even trying to install it.

Since I finally got a basic Tomcat instance up and running, I won't delete it. However, the next time I'm working on a Java-based webapp, I'm going to try some alternatives to Tomcat. I've heard good things about Jetty and Glassfish. There are others, as well. Tomcat used to be pretty handy, but now it's evolved to the point that there's more administrative overhead involved with it than the value it returns, for purposes of development. It's still a nice servlet container when used in conjunction with Apache HTTP Server in production, but I'm done using it as a development tool unless and until they make it work smoothly.

Next: Installing .NET development support

Installing Java support

Previous: Installing Ruby testing tools

Since my system was trashed anyway, I decided to take the opportunity to apply lessons learned over the past few months of using Ubuntu as my primary work platform. I didn't reinstall exactly the same tools as before for Java development. I want to check out some different tools for building, version control, and continuous integration. This time around, I just installed the basic Java tools.

If you're curious about experiences with installing maven2 and/or migrating Java projects from Mac OSX to Linux, please see this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-java.html.

These commands get the latest and greatest JDK and make it the system default.

sudo apt-get install sun-java6-jdk sun-java6-plugin
sudo update-java-alternatives -s java-6-sun

Although Java is available for free, it is not Open Source. The Java install will prompt you to agree with license terms. So, don't expect to "fire and forget" this installer.

To verify that Java 6 is the system default, check the default version:

java -version


Next: Installing Tomcat

Installing Ruby testing tools

Previous: Installing Rails

These are tools for test-driven-, behavior-driven-, and storytest-driven-development:

* Autotest - continuous testing (part of ZenTest)
* Cucumber - storytest tool
* RCov - coverage tool
* rspec - BDD tool
* Webrat - browser simulator (used by Cucumber)

On Debian variants (like Ubuntu), you have to install a couple of libraries before installing Webrat. They are needed by Nokogiri, the XML libary used in Webrat.

sudo gem install ZenTest
sudo gem install rcov
sudo gem install rspec rspec-rails
sudo gem install cucumber
sudo apt-get install libxslt1-dev libxml2-dev
sudo gem install webrat


Next: Installing Java support

Installing Rails

Previous: Installing MySQL and Ruby bindings

Use Gems to install Rails. Open a Terminal window and enter

cd ~
sudo gem install rails

If the installation succeeded, the following command will display version information:

rails -v

Next: Installing Ruby testing tools

Saturday, April 10, 2010

Installing MySQL and ruby bindings

Installing MySQL and ruby bindings

Previous: Installing basic ruby support

MySQL Server


In Terminal, install MySQL Server with apt:

sudo apt-get install mysql-server

During installation, you will be prompted to enter a password for the root mysql user. While it's possible to run mysql with no root password, it's generally considered a good practice to use a password.

The installation will automatically start the server. To verify the installation was successful, check to see if the server is running:

ps ax | grep mysql

You can also check for the existence of this file, which exists when the server is running:

/var/run/mysqld/mysqld.pid

The commands to stop and start MySQL Server are

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

If you want to stop the server while continuing to install software, you can do so.

MySQL command-line client


I wanted to configure MySQL to put database data somewhere under my /home directory because it's in a large partition and so that it will be easy to backup and restore my data. To do this, I created the data directory and set permissions so mysql could use it:

cd
mkdir -p .mysql/data
chown mysql .mysql .mysql/data

Now stop the mysql server.

Edit the file /etc/mysql/my.cnf. Look for the section labeled [mysqld] and change (or add) the datadir specification:

datadir=/home/you/.mysql/data

After making those changes, start the server.

To see if the configuration changes worked, start a command-line client

mysql -u root -p

If it starts normally, then the server is running and the localhost connection is working. To ensure mysql is using the datadir you specified, create a test database:

create database test1;

Exit the command-line client by typing "quit". Change to the directory you specified as datadir. If you don't have permission to cd to the directory, use sudo to add read and execute privileges on it. (You need execute privileges to cd to a directory.)

MySQL GUI client


From the main menu bar, choose Applications > Add/Remove....

1. If prompted to update the list of available packages, do so.

2. Under Show, choose All available applications.

3. A few applications may be pre-selected for you. Browse the list and see if you really want any of these. De-select the checkboxes for the ones you don't want. In some cases, the system will warn you that other packages depend on the one you're trying to de-select. In that case, you will need to install it.

4. Select "MySQL Administrator" for a GUI client and "MySQL Query Browser" for a GUI tool to run queries. (If you type "my" in the Search: field, the list will jump right to these entries.)

5. Choose Apply Changes to proceed with the installation. If any of the applications requires administrator rights to install, the system will prompt for your administrator password. This is normal and not an exploit.

After the installer finishes, the two applications will appear under Applications > Programming from the main menu bar.

To ensure MySQL Administrator was installed correctly, with the MySQL server running, go to Applications > Programming and select MySQL Administrator from the menu. The program should open a window containing a form where you can enter connection information. Enter "localhost" for host, "root" for user, and the password you defined earlier for password. If you didn't define a password earlier, then leave the password field empty. Choose Connect.

Check the installation of MySQL Query Browser in the same way.

Install Ruby bindings for MySQL



Open a Terminal window and enter the following commands:

cd ~
sudo apt-get install libmysql-ruby libmysqlclient-dev

The package libmysqlclient-dev is a virtual package. When you run the command above, you will see an error message that shows the name of the real package. Substitute it in the command line and run it again. When I ran it, it showed libmysqlclient15-dev, so I ran the command this way:

sudo apt-get install libmysql-ruby libmysqlclient15-dev

Run this command to build it:

sudo gem install mysql

Expect a lot of error messages for missing definitions in ri and rdoc. As long as the gem and native extensions build okay, you're good to go.

Next: Installing Rails

Friday, April 9, 2010

Installing basic ruby support

Previous: Rethinking directory structure

Still recovering from the system problem reported earlier.

I documented this before, but I've learned a few things since then so some of these steps may be a bit different. If you're using this as a guide for setting up your own Ubuntu system, I'd suggest using the latest posts on each topic.

First, I need support for git:

sudo apt-get install git-core

I want to install various software development tools. Let's start with Ruby. I'll take care of plug-ins and so forth later, when setting up specific projects. For the moment I just want to get basic tools installed.

sudo apt-get install ruby-full

and verify it worked

ruby -v

Also need ruby gems support. The ruby community reports problems when apt is used to install rubygems. The following procedure is recommended instead.

Take your browser to http://rubyforge.org/frs/?group_id=126. In the list of available downloads, hover the mouse cursor over the name of the one you want to see which URL would be downloaded (but don't download it yet). In my case, the URL was http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz.

The key elements to note are the numerical path segment 69365 and the version number, 1.3.6. These elements will vary as new releases are posted. Not very RESTful, I suppose.

Armed with this information, get rubygems this way:

cd ~
wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
tar xzvf rubygems-1.3.6.tgz
cd rubygems-1.3.6
sudo ruby setup.rb

The setup.rb script will display the name of the rubygems executable on the console, like this:

RubyGems installed the following executables:
/usr/bin/gem1.8

Use the name to set a symlink like the following

sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

and verify it worked

cd ~
gem -v

It will display the version number of gems that is installed. This should match the version number you found on rubyforge.

Now you can delete the installation directory and the tarball:

rm -r rubygems-1.3.6
rm rubygems-1.3.6.tgz

Note that the software is installed under /usr. This is the reason I decided to mount /usr from its own partition. I will be able to repair or upgrade Ubuntu itself without having to reinstall all my software piece by piece.

Next: Installing MySQL, admin tools, and ruby bindings

Rethinking directory structure

Previous: Interesting times

Recovering from interesting times



So, I've got most of my work on an external drive and I've got a nice fresh /home in its own partition. Why not just slap the contents of the backup into /home and declare victory? Well, a fair amount of cruft has accumulated in my /home directory. It could be organized more conveniently. I've got various software development tools installed here and there, and shell scripts in various places. And I really don't need all the jar files and libraries and sample code and old projects and local maven repo and copies of articles to read in my spare time and on and on and on. It's just clutter.

I took the time to decide what I really need on this machine and how it should be organized, and then selectively restore those items from the backup. I also decided to reinstall just the software that I'm actively using, rather than to reinstall everything that had been on the system before.

The default /home directory structure is:


/home
|
+---- Desktop
|
+---- Documents
|
+---- Music
|
+---- Pictures
|
+---- Public
|
+---- Templates
|
+---- Videos


Microsoft Windows and Mac OS X also ship with a similar default directory structure. The default structure is only a suggestion, to help novice computer users get started. But I just don't organize information according to file type (music, pictures, videos, etc.) I keep files that pertain to a given topic together, whatever their various formats and types. I decided to define a structure that reflects the way I usually think about what I'm doing with the computer.

At the highest level, I don't want to have to look at a million folder names to find what I'm looking for. It boils down to this:


/home
|
+---- Desktop
|
+---- Personal
|
+---- Professional
|
+---- .bin


I changed the top-level directory structure just below /home to the above, and removed the old directory names from the Places pane.

Next: Installing basic ruby support

Interesting times

Previous: Microsoft drives another Windows user to Linux

Interesting times


My Ubuntu system had a bad night. I deleted some files from my external hard drive. When I clicked on "empty the trash," odd things started to happen. The external drive's filesystem switched to read-only mode. No error messages that I could find. At some point while I was fiddling around to try and clear out the trash folders, either I did something inadvertently or a glitch in the driver corrupted part of the Ubuntu kernel.

Now Ubuntu couldn't mount filesystems on the internal hard drive. I tried rebooting, on the chance that a fresh start would clear up whatever was wrong. No such luck. Now Ubuntu couldn't boot.

Using someone else's system and Internet connection, I searched for help. I discovered this sort of thing has happened to other Ubuntu users. Apparently the only thing to be done is to reinstall fresh.

The downside: My system was dead in the water. I was in a hotel room, far from any helpful resources I might have had in my home office.

The upside: I had a backup of my work from a few days earlier. I had bootable CDs with me for Ubuntu 9.10 and 9.04. I had my Firefox bookmarks online on XMarks, where I could sync them when ready. Finally, this very blog contains instructions for installing and configuring my system, and warnings about what not to do, just in case I've forgotten. Things could have been so much worse!

Recovering the system


I decided to take the opportunity to do a bit of housecleaning and to apply some of the lessons learned so far in my n00b journey. My hard drive had a dual-boot configuration with Ubuntu and Microsoft Windows Vista. It occurred to me that I hadn't even thought about booting into Windows in the past few months. Why use up half the hard drive space with Windows partitions?

More housecleaning: I had read that most Ubuntu users define a separate partition for their /home directory. It makes upgrades easier, since you can install a new release of the OS in the root partition and keep your /home intact. Another thing I've learned is that /usr/local and /usr/share are updated when you install software and customize gnome. You don't have to install things in those locations, but they are default locations. With that in mind I wiped the drive and created the following partitions:

* /
* /usr
* /home
* swap

I tried installing from the 9.10 disk, and had problems. Again using someone else's system to look for help, I learned that 9.10 has some known kernel issues, one of which is that it doesn't support the wireless adapter that my machine has (Intel AGN 5100). It also seemed to have problems mounting the /home and /usr partitions. No helpful error messages.

Next I installed from the 9.04 disk, and had similar problems booting and mounting the partitions. I also noticed that there was no driver for the wireless adapter and that audio was disabled. I remembered that these problems had been fixed at some stage in the evolution of 9.04, and surmised that I had an old release of Ubuntu on that disk.

I installed from the 9.04 disk again, this time defining just one partition for the whole OS. This instance could boot, but had no network support. Again using another system, I downloaded the last stable Ubuntu 9.04 iso from releases.ubuntu.com/9.04 to a thumb drive, and used the old 9.04 instance to burn it to a DVD.

This version of 9.04 installed nicely into the partitioning scheme described above and booted without complaint. I felt like the Apollo 13 astronauts after they'd restarted the Command Module. Well, okay, maybe that's a stretch.

Update mistake


To bring the new instance up to date, I opened a Terminal window and ran these commands:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get build-essential


At this point I made a mistake. I used Update Manager to check for available updates and install them. After more than two hours, the update process became confused when trying to install a package. The process hung, and the last message on the console was "stopping bluetooth." I waited a while just in case it was doing something under the covers, but ultimately I killed the process and rebooted. The system was very confused about what was installed and what wasn't. Network support was gone again.

Since I was still early in the recovery process, I just reinstalled from scratch again. This time, after running the update commands in Terminal, I didn't try to do any updates through Update Manager.

To the contrary, I started the gnome configuration editor (alt+F2, enter gconf-editor, click Run), went to apps > Update Notifier, and deselected the auto-run checkbox. This is to protect myself from responding to the prompt about available updates. I'll update packages that are flagged as dependencies for software that I want to install. Otherwise, I'll stick with the working version of 9.04.

Next: Rethinking directory structure