Saturday, May 7, 2011

Installing Self-contained Executables in Ubuntu

Since I started using Ubuntu/Linux about 5 years ago, I've enjoyed an array of open-source programs available to me for free download. Many of the programs I make daily use of like office suites, web authoring interfaces, browsers, media players and system tools. This development has allowed me to largely abandon Windows as a platform except for the rare instance when I must use it for client work.
But there are several programs I use that are not available in the Ubuntu repositories. They're programs that are not supported or recommended by Canonical, or are specialty, proprietary programs for which a GNU/Linux version is available, but not packaged for a particular distribution by the developer. These programs are usually provided in the form of a self-contained binary that, once extracted from its compressed archive, will run directly from the location of the extracted directory on the system. This poses a small challenge for someone who likes a tidy filesystem. If you extract the folder to your home directory, it's only available to you from the user account you originally installed it on. If you extract it to your Desktop, well, that's just not very orderly.
In this post, I'll show you how to download an archive with a self-contained executable program and extract it in a central location available to you from any user account (or multiple users on a shared system). You'll also learn how to link the program command to a common folder in your $PATH and how to create a menu shortcut to easily access the program for all time (or until you scrap your partition and install a fresh OS). This demonstration will be performed with Ubuntu 11.04 (classic GNOME). Older versions of Ubuntu will most likely be identical for the purpose of this tutorial. We'll also be using the command line. Let's get started.
Download and install the program
Follow this link to the download page for Mozilla Sunbird, a standalone calendar program (Sunbird is no longer in development and is not in the Ubuntu repositories for 11.04). Download the archive for “Linux x86, English” to your Desktop (or “Linux x86-64, English” if you're running a 64-bit version of Ubuntu). At this point, open up a Terminal window and switch your working directory to the Desktop: cd Desktop
Now, you'll need to move the archive to a more central location where the program will eventually run from. I like to use the /usr/local directory. Also, since you're working in a system directory, you'll need to make use of the “Super User” command or “sudo”: sudo mv sunbird-1.0b1.tar.bz2 /usr/local/ (to avoid typing lenghty file names, you can type the first few letters and hit “tab” to let Bash auto-complete the file name for you). Type in your password when prompted. Now, change your working directory to “/usr/local/” by typing cd /usr/local/
Type the command ls to list the contents of /usr/local/ You can see that the compressed archive was successfully moved. Now we must extract the program files and directories from the archive: sudo tar -xjf sunbird-1.0b1.tar.bz2
At this point, let's open a file manager window and see what we've done. Open your home folder, type ctrl.+L and type /usr/local/sunbird/ into the address bar. See all the files you've put in the /usr/local/ folder? If you double-click on the file named “sunbird” it will launch the Sunbird Calendar (click the “Run” button when Ubuntu asks about whether to run the executable file or display its contents). From here on out, Ctrl.+click any images to view them at full size in a separate browser tab or window.

Place a link to the program in your $PATH
Now that Sunbird is successfully installed, let's place a convenient link to the program in your $PATH. Your $PATH is a list of directories your system looks in when you issue a command, to launch a program for example. If a command is not in your $PATH, Ubuntu will complain to you that the command you requested doesn't exist. /usr/local isn't in your $PATH, so we're going to create a link to Sunbird in a directory that is. This will save you from having to type /usr/local/sunbird/sunbird to launch the program. Instead, you can just tell Ubuntu, sunbird and Ubuntu will dutifully oblige. To learn which directories are in your $PATH, type echo $PATH in a command terminal.
The directory /usr/local/bin/ is a subdirectory of /usr/local/ (where the sunbird directory is now located), so that's an obvious choice. Create a link in that directory by typing sudo ln -s /usr/local/sunbird/sunbird /usr/local/bin
Go back to your file manager and click through to /usr/local/bin. Now you can see that there is a link named “sunbird” Double-clicking this link will launch the program. The Sunbird Calendar program is now installed, and a link is now conveniently located in your $PATH.

Cleaning House

Now that Sunbird has been successfully installed, we can get rid of the downloaded archive. Back in the terminal window, type in sudo rm sunbird-1.0b1.tar.bz2 Listing the contents of /usr/local/ by typing ls will reveal that the archive has been deleted.

Create a menu shortcut

You've now installed Sunbird globally on your system and can launch it from a terminal by simply typing sunbird But how 'bout a menu launcher? Ubuntu makes it easy. First, right-click on the menu icon in the top-left panel and select “Edit Menus.” That will open a new dialog.

In the left pane, choose the “Office” category. Then, in the right pane, click the “New Item” button.

In the “Create Launcher” dialog, give the program the name “Sunbird.” Type in "sunbird" (without the quotes) for the command and then write a brief description. Finally, click on the launcher icon button to the left.

In the window that opens, browse to the best icon for Sunbird (/usr/local/sunbird/icons/mozicon128.png) and select it. Then click “Open,” and then click “OK” back in the “Create Launcher” dialog.

Now, close the “Main Menu” dialog to quit editing the menus. Click on the main menu icon in the top left panel, highlight “Office” and then “Sunbird” and then click “Sunbird.” Sunbird now opens.

Congratulations! You've just globally installed a self-contained executable, created a shortcut in your $PATH and added a custom launcher to your main GNOME menu. Isn't GNU/Linux great?

No comments:

Post a Comment