- How to build a Debian/Ubuntu package from source?
- How to Compile and Install Software From Source in Linux
- Step 1: Installing the Required Tools
- Step 2: Downloading the Package Source Code
- Step 3: Compiling the Source Code
- Step 4: Building the Software Package
- Step 5: Installing the Software Package
- Alternative Methods of Installing Software on Linux
How to build a Debian/Ubuntu package from source?
you can use the special package «checkinstall» for all packages which are not even in debian/ubuntu yet.
You can use «uupdate» ( apt-get install devscripts ) to build a package from source with existing debian sources:
apt-get build-dep libdrm2 apt-get source libdrm2 cd libdrm-2.3.1 uupdate ~/Downloads/libdrm-2.4.1.tar.gz cd ../libdrm-2.4.1 dpkg-buildpackage -us -uc -nc
Thanks! I have just used this to port Subversion 1.6.6 to an Ubuntu install that only has 1.6.5 as its latest available version, and it worked flawlessly. Saved me quite a few hours of tinkering! 🙂
Could you give a little more context around these commands? Where is libdrm-2.3.1 exactly? Also where did libdrm-2.4.1.tar.gz come from (my initial assumption is that is the compiled binary of the application that we want to package in a deb, but replacing the existing version, is that correct?)
If you get the error You must put some ‘source’ URIs in your sources.list , uncomment the deb-src lines in your /etc/apt/sources.list
First, the title question: Assuming the debian directory is already there, be in the source directory (the directory containing the debian directory) and invoke dpkg-buildpackage. I like to run it with these options:
dpkg-buildpackage -us -uc -nc
which mean don’t sign the result and don’t clean.
How can I check if I have listed all the dependencies correctly?
Getting the dependencies is a black art. The «official» way is to check build depends is if the package builds with only the base system, the «build-essential» packages, and the build dependencies you have specified. Don’t know a general answer for regular Dependencies, just wade in 🙂
How I can I prevent the update system installing the older version in the repo on an update? How I can prevent the system installing a newer version (when its out), overwriting my custom package?
My knowledge might be out of date on this one, but to address both: Use dpkg —set-selections. Assuming nullidentd was the package you wanted to stay put, run as root
echo 'nullidentd hold' | dpkg --set-selections
Alternately, since you are building from source, you can use an epoch to set the version number artificially high and never be bothered again. To use an epoch, add a new entry to the debian/changelog file, and put a 99: in front of the version number. Given my nullidentd example, the first line of your updated changelog would read:
nullidentd (99:1.0-4) unstable; urgency=low
Bernard’s link is good, especially if you have to create the debian directory yourself — also helpful are the developers reference and the general resource page. Adam’s link also looks good but I’m not familiar with it.
How to Compile and Install Software From Source in Linux
Although Linux has package managers that make software installation much easier, sometimes you’re forced to build a package from the source.
Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.
Do you want to fix a bug in a software package, or do you simply want to modify a package to meet your needs? Linux has got you covered.
Most Linux packages are free and open-source, giving you the freedom to customize or modify any piece of software to your own liking. Additionally, you are also free to look at the source code of Linux packages to learn good architecture practices and coding patterns from other software projects.
Let’s explore how you can compile and install a package from source on Linux.
Step 1: Installing the Required Tools
Linux provides you with all the necessary tools required to compile, build, and install software from the source code.
Most Linux software is written in the C or C++ programming languages, therefore, you’ll need a C or C++ compiler. For example, the GNU Compiler Collection (GCC) and CMake for building your package.
Besides that, you’ll need other packages such as curl and gettext. Depending on your Linux distro, you can install the required tools in a single command as follows.
On Debian-based distros such as Ubuntu:
sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc curl
On Arch Linux and its derivatives:
On RPM-based distros such as Fedora, RHEL, etc:
sudo dnf install dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel gcc curl cmake
Step 2: Downloading the Package Source Code
For this guide, we’ll be installing the Git package from the source. We’ve chosen Git because it is widely used among software engineers and developers.
Most packages you can compile can be found on the official website of the package in question. You can download the source code files using the curl command-line tool. Alternatively, you can use wget or the GUI.
Download the source code into the Downloads folder on your PC, then, switch to the Downloads directory using the cd command.
Once you’re in the Downloads folder, you can download the Git source code using curl as follows. In this guide, we’ll download the Git version 2.26.2 but feel free to choose any version.
curl --output git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz
The curl command specifies that it should place the source code in a zipped file named git.tar.gz.
In most cases, the source code will be packaged in a compressed folder to make downloading easier and for better organization of the source code files.
To extract the content of the zipped file, you can use the tar command.
Step 3: Compiling the Source Code
Next, go to the newly extracted folder. In this case, the name will be «git-2.26.2,» of course, the folder name will be different if you have downloaded a different version of Git.
It is always a good idea to take a look at the README.md or INSTALL files because they contain valuable information on how to compile and install the package. These files are usually located in the root folder of the source code.
Another important file is the configure script. It checks for software dependencies for the package you want to compile, and you’ll see an error message if the script finds missing dependencies.
Configure and prepare your source code by executing the script. The command will create make files and configurations for the software that you are about to compile and install.
Step 4: Building the Software Package
Now that the source code is configured and compiled, you can build the software as follows:
The make command uses the Makefile, which contains necessary instructions on how to build the software package.
The compilation process will take some time depending on your computer’s processing power, and the size of the package.
Step 5: Installing the Software Package
If you’ve come this far, congratulations, you’ve successfully compiled and built Linux software from source code.
In this last step, you’ll install the Git software package you’ve just built from source code. This command installs the newly compiled package by copying the build files to the correct locations on your PC.
Check the version of Git you just installed with the command:
The output should be similar to the one below. The version number may vary depending on the package that you downloaded.
Alternative Methods of Installing Software on Linux
This guide has looked at how to compile and build software from source on Linux using Git as a study case. Installing software from source code gives you so much freedom to customize the software to your liking which is an amazing thing.
Most Linux distros provide you with many options when installing software. For example, on Arch Linux, you can use Pacman and Yay package managers.