When you first take control of your Linux server on NameHero, you’ll have a lot of set up to do. There is the security aspect, for which you need to harden the server. Then you have to install the usual software like a web server, and whatnot. Most of the time, you’ll be working with (hopefully) standardized installations of Linux. This means that you will be able to use the in-built package manager to install and uninstall your software.
This is, in fact, the preferred way of doing things. Unlike working with an operating system like Windows, where you can just download an installation file and let it run automatically, Linux has many repositories of software packages that you can subscribe to and install with a few commands. However, sometimes you’ll find a package that hasn’t been compiled for your particular flavor of Linux. Or perhaps not compiled at all!
In such a situation, you’re going to need to download the source code and compile it yourself. Unfortunately, not all programs are well-written, which may pose problems for uninstalling the software later on – which is why this is only a last resort. Not to mention that it may contain malicious code that’s dangerous to your server. But if you need to do it, here’s how to go about it.
1. Ensure that The Compiling Tools are Installed
If you’ve purchased a VPS on NameHero, you’ll find that the compilation tools are installed automatically. You can test this using the following command:
If the tools are present, you’ll get an output like this:
Otherwise, you’ll see something like “Package not found”. If you see this message, it means you have to download and install the appropriate development tools. For CentOS, the command to do that is:
sudo yum groupinstall "Development tools"
If you haven’t done so already, make sure you’ve disabled root access and given another user sudo permissions.
2. Download and Extract the Source Code (Typically tar.gz)
It’s common practice to package source code directories into “tar.gz” files for downloading to Linux systems. Using the “wget” command, we can download the file from a specific URL like this:
wget [url of source file]
This will download it into the current directory. To extract it into a default new folder, use the following command:
sudo tar -zxfv [name of the file]
This will create a new directory with the extracted contents of the source file.
Optional: Change New Directory Permissions
The new directory needs the “execute” permission, which some Linux systems don’t automatically create. Without this, you can’t enter or “cd” into the directory. To change this, use the following command:
sudo chmod 2775 [directory name]
Now we’re ready to compile!
Compile the Source Code and Running the Program
Go to the directory and once inside, type the following commands:
./configure make sudo make install
Each of these commands can take some time to execute. Compiling a program is a CPU intensive process, and depending on the complexity of the source code, it could be a while before you’re done! But if everything goes smoothly, you should now be able to run the program command from inside the directory.
If you want to execute the program from anywhere in the shell (and not just from within the directory), you’ll need to modify the environment variables, which I’ll show you how to do in another article.
Uninstalling the Program
To uninstall, you have to pray that the program creator has created a script specifically for this purpose. If they have, you can uninstall using the command:
sudo make uninstall
If there is no such program, you’ll have to manually go and remove every single file that the compilation process created. It’s time consuming and hard. Which is why it’s generally preferable to never do this in the first place! But sometimes, you have no choice.
And that’s it. Hopefully, this will be a rare occurrence for you to compile and run a program in Linux. But if you absolutely have to, the above the way to go about it.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!