{"id":2222,"date":"2019-02-12T22:07:25","date_gmt":"2019-02-12T19:07:25","guid":{"rendered":"http:\/\/kifarunix.com\/?p=2222"},"modified":"2019-02-12T22:07:25","modified_gmt":"2019-02-12T19:07:25","slug":"how-to-install-programs-from-source-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-install-programs-from-source-on-ubuntu-18-04\/","title":{"rendered":"How to Install Programs from Source on Ubuntu 18.04"},"content":{"rendered":"<p>In this guide, we are going to learn how to install programs from source on Ubuntu 18.04. More often than not, the easiest and hustle free method of installing programs on Ubuntu 18.04 or the whole Linux family is to use the respective distribution package manager. This ensures that you are installing a software that is optimized for your distribution. It also eliminates the issue of having to deal with annoying dependencies. However, there is a point in time when you need to install the latest version of a software to patch some bug or test a new feature or even a software that is not available on your distribution repositories. In this case, then you need to download the source code of the program, compile and install it.<\/p>\n<p>Therefore, in this guide, you going to learn how to;<\/p>\n<ul>\n<li>Unpack source code using common compression and archive utilities<\/li>\n<li>Use <code>make<\/code> to compile programs<\/li>\n<li>Apply parameters to a configure script<\/li>\n<li>Know where sources are stored by default<\/li>\n<\/ul>\n<h2>Install Programs from Source on Ubuntu 18.04<\/h2>\n<p>You first need to download the software tarball from the trusted sources before you can proceed.<\/p>\n<h2>Unpacking the Source Code<\/h2>\n<p>Opensource software is always distributed as a compressed tarball. The tarball contains the program source code which basically contains all the necessary scripts for compiling and installing the software.<\/p>\n<p>There are various tools that can be used to compress the source code tarballs. The most common ones include <code>gzip<\/code>, <code>bzip2<\/code>, <code>xz<\/code>. So how do you unpack the tarball that has been compressed using the various formats of the above tools.<\/p>\n<h3>Unpacking <code>.tar.gz<\/code> or <code>.tgz<\/code> tarballs<\/h3>\n<p>To unpack the tar.gz or .tgz, you would use any of the following commands;<\/p>\n<p>Using <code>gunzip<\/code> or <code>gzip<\/code>.<\/p>\n<pre>gunzip -dc tarball.tar.gz | tar xf -\r\ngunzip -dc tarball.tgz | tar xf -<\/code><\/pre>\n<p>Using <code>tar<\/code> command;<\/p>\n<pre>tar xzf tarball.tar.gz\r\ntar xzf tarball.tgz<\/code><\/pre>\n<h3>Unpacking <code>.tar.bz2<\/code>,\u00a0<code>.tar.bz<\/code> or <code>.tbz<\/code> tarballs<\/h3>\n<p>Using <code>bzip2<\/code>, <code>bunzip2<\/code>.<\/p>\n<pre>bzip2 -dc tarball.tar.bz2 | tar xvf -\r\nbzip2 -dc tarball.tbz2 | tar xvf -\r\nbzip2 -dc tarball.tbz | tar xvf -<\/code><\/pre>\n<p>Using <code>tar<\/code> command;<\/p>\n<pre>tar xjf tarball.tar.bz2\r\ntar xjf tarball.tbz2\r\ntar xjf tarball.tbz<\/code><\/pre>\n<h3>Unpacking <code>.tar.xz<\/code> or <code>.txz<\/code> tarballs<\/h3>\n<p>Using <code>unxz<\/code> or <code>xz<\/code> command;<\/p>\n<pre>unxz -dc tarball.tar.xz |tar -xf -\r\nunxz -dc tarball.txz |tar -xf<\/code><\/pre>\n<p>Using <code>tar<\/code> command;<\/p>\n<pre>tar xJf tarball.tar.xz\r\ntar xJf tarball.txz<\/code><\/pre>\n<h3>Building a Program from source<\/h3>\n<p>Before you can build a program from the source, you need to install the GNU C compilers and libraries that are required for a successful compilation. Therefore, you need to install the <a href=\"https:\/\/packages.ubuntu.com\/bionic\/build-essential\" target=\"_blank\" rel=\"noopener\">build-essential<\/a> package that provides all these compilation tools.<\/p>\n<pre>apt install build-essential<\/code><\/pre>\n<p>You also need to check list of dependencies that the program in question requires. This information can be obtained from the documentation of the program in question.<\/p>\n<p>Once you have extracted source code from the tarball, you need to <code>configure<\/code>, <code>compile<\/code> and <code>install<\/code> it. The preferred way of installing a package from source is usually included in the README or INSTALL files in the tarball. You can check these files on how to best build the specific package.<\/p>\n<p>However, in most cases, a configuration script, <code>configure<\/code>, contained in the source code directory is usually executed as shown below;<\/p>\n<pre>.\/configure<\/code><\/pre>\n<p>The common syntax of the configure script is;<\/p>\n<pre>.\/configure [OPTION]... [VAR=VALUE]...<\/code><\/pre>\n<p>The configuration script is generated using the <code>autoconf<\/code> utility. This script adapts the software to the system. It also checks for availability of all the dependencies required to successfully build the software. The dependencies can either be optional or mandatory.<\/p>\n<p>If an optional dependency is missing on the target system, the compilation of that dependency is disabled. However, if a mandatory dependency is missing from the target system, the script will print the related error and exit.<\/p>\n<p>The configure script gives you the ability to optimize how compilation will happen. For example, you can change the installation path of the software by passing the <code>--prefix=\/path\/<\/code>. <code>\/usr\/local\/<\/code> is usually the default installation path.<\/p>\n<p>In order to find more options that can be used with the <code>configure<\/code> script, run the command;<\/p>\n<pre>.\/configure --help<\/code><\/pre>\n<h3>Compiling the software<\/h3>\n<p>The <code>make<\/code> command is used to compile and install the software. When the configure script is run, it generates a file called <code>Makefile<\/code> with a series of steps and all the information required to build and install the software. Hence to compile a program, just invoke the <code>make<\/code> command.<\/p>\n<pre>make<\/code><\/pre>\n<p>Once the compilation is done, you need to invoke make command with the <code>install<\/code> option in order to install the program files in their proper directories.<\/p>\n<pre>sudo make install<\/code><\/pre>\n<p>Note that you need to run this command with elevated privileges lest you get the permission denied errors due to lack of write permission to system directories.<\/p>\n<p>Your program binaries will finally be installed to <code>\/usr\/local\/bin<\/code> if at all you didn&#8217;t change the default install path during configuration. If this directory is not in your path, you can either add the path to your PATH or create a symbolic link of your program from <code>\/usr\/local\/bin<\/code> to <code>\/usr\/bin<\/code>.<\/p>\n<p>If you however need to remove stale program object files or uninstall the program, you need to run the following commands below respectively. Note this is only possible if you have not deleted the source code directory.<\/p>\n<pre>make clean\r\nmake uninstall<\/code><\/pre>\n<p>Well, that is all about how to install programs from source on Ubuntu 18.04. You should now comfortably build and install any software on Ubuntu 18.04. All the best.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn how to install programs from source on Ubuntu 18.04. More often than not, the easiest and hustle<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121],"tags":[326,124,328,325,329,123,327,67],"class_list":["post-2222","post","type-post","status-publish","format-standard","hentry","category-howtos","tag-configure","tag-make","tag-make-clean","tag-make-install","tag-make-unistall","tag-source-code","tag-tarball","tag-ubuntu-18-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2222"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=2222"}],"version-history":[{"count":2,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2222\/revisions"}],"predecessor-version":[{"id":2224,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2222\/revisions\/2224"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=2222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=2222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=2222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}