Showing posts with label apt-get. Show all posts
Showing posts with label apt-get. Show all posts

Saturday, March 28, 2009

Building From Source using Apt-get in Ubuntu

As a reasonably dedicated Debian/Ubuntu user, I often find myself at a disadvantage compared to Gentoo users who compile everything from source. Compiling from source can often yield huge performance gains over just installing binaries provided by your distribution. Luckily, the apt-get system provides users the ability to compile from source just as Gentoo users can.

The first step in compiling from source is issuing
sudo apt-get build-dep package_name
where package_name is the name of whatever package it is you are planning on compiling.

The sudo at the beginning of this step is important, as it gives you the necessary permissions to perform the apt-get part of the command. Issuing the apt-get build-dep command prompts apt-get to install binaries for whatever is required to build the package you specify, from things as simple as basic as the GCC compiler to as complicated as the Gtk developer headers, and any other library the program you are compiling depends on.

After you have installed all of the requirements to build a package, the next step is issuing the

sudo apt-get -b source package_name
where package_name is again the package you are compiling. This is the step that actually does the compiling, so it can take a while. What you are left with after this step is completed is a .deb file in your home directory.

Finally, to install the package you just compiled, there are two options. If you navigate to your home directory in Nautilus and double-click the .deb file you've created, gdebi-gtk will take care of you as far as installing the package is installed. If you prefer to install via the command line, dpkg is the necessary tool.

To install from the command line, first type "cd". Issuing the cd command by itself returns you to your home directory, no matter where you are in the file system. The apt-get -b step places the package in your home directory, so this is where we need to be. Finally, issuing the command "sudo dpkg -i package_name" will install the package that you've just compiled. Once again, the sudo portion of the command is required, as a normal user as is the default in Ubuntu does not have the required permissions to install new software.

If you ever seek to remove the package, you can do so by issuing the "dpkg -r package_name" command. The -r in this case stands for remove.