*NIX Tricks

[linux] How to install a package from the source code

Posted in linux, osx by kousik on October 31, 2009

Installing a package (AKA software) from source code is often considered to be the secret cult of the worshipers of the Geek God. But, you know, it’s not that difficult. Let’s see how we can do it.

First, some preliminaries. Why should I build it form the source code? Well, source codes are more or less platform independent. If you have a suitable compiler and necessary libraries, you may install it on any platform of your choice. Source code files are available  in ASCII plain text  format (not binaries) — so you can study it and understand what it does and whether/ how it may affect your system. Reading  the description of a software distributed as a binary does not even come close to that — you really don’t know what that piece of  software does until you actually run it. Needless to add, you may include your changes to the open-source code to suit your needs as well in accordance with the relevant license.

Secondly, where can I find the source code? The source code for a open-source package is often distributed in compressed format (i.e., with an extension “tar.gz”, “tgz” or “tar.bz2” — that’s why it’s also called tarball). You may download the tarball from a reliable source, e.g. homepage of the package developer, Free Software Directory, Open Source Software directory, linux.org, Ubuntu archive, Darwin ports, Fink and Open Source Apple website. Last three are specifically intended for OSX running Darwin. Wikipedia also has a nice list of Free and Open Source softwares.

Now, let’s do the installation step-by step. Create a directory (say, ~/packages) where you want to save the packages, navigate to that directory, save the tarball (say, newpack.tar.gz) there and uncompress it:

$ tar zxvf newpack.tar.gz

Replace “zxvf” by “jxvf” if it has a “tar.bz2” extension instead of “tar.gz” or “tgz”.

Then navigate to the uncompressed directory (usually newpack, but be sure of  that first using the ls command) using

$ cd newpack

and read the instruction files (e.g., INSTRUCTIONS, INSTALL, README), if any, for special instructions using your favorite text editor. Otherwise, the normal procedure for installation is the following series of commands: (wait for each one to finish before you issue the next command!)

$ ./configure
$ make
$ sudo make install

You need to enter the superuser password in the last step as it copies the executable in the system’s executable directory (e.g., /bin, /sbin/). That’s it!

However, you may want to clean up the mess (especially the object files) created by the installation process using:

$ make clean

In a spree of cleaning up, however, don’t delete the file named Makefile: you need this if you want to uninstall the package (the above command won’t delete it).

In order to uninstall the package, navigate to the same directory (~/packages/newpack/), and issue the following command:

$ sudo make uninstall

You need to enter the superuser password for this.

Reference: here.

[ubuntu] Unlock /var/lib/dpkg/lock when you’re locked out

Posted in ubuntu by kousik on October 2, 2009

You must have seen this (that’s why you’re here after all!)


E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

This often happens if you try to install a package (say, <package-name>) while you are installing another. As an example, this may happen when you try to run
$ sudo aptitude install <package-name>
in the terminal while you have Synaptic package manager open (or vice versa) or in another terminal you are installing another package . The easiest solution is just to wait for the other installation(s) to finish  and close the package manager if you are done with it. However, if the package manager is crashed in the middle some stuck-up  processes may still be using the lock (/var/lib/dpkg/lock).

In that case, use fuser to find out the runaway process(es); and while you’re at it, you may use -k flag which will kill the process that is still using /var/lib/dpkg/lock. Then configure (--configure) all the packages (-a) which are yet unpacked and unconfigured, using dpkg:


$ sudo fuser -vki /var/lib/dpkg/lock; sudo dpkg --configure -a

In the first command (fuser), the -i flag asks for user confirmation, and -v is for verbose mode.

After that, proceed to the usual installation step of the package that you want to install.

[cli] Install .deb packages in the commandline

Posted in cli by kousik on September 16, 2009

You may use package installer like gdebi to install .deb packages. But would it feel as good as it does when you do it in the commandline?

$ sudo dpkg -i name-of-your-package.deb

Reference: here.

Follow

Get every new post delivered to your Inbox.