How to Install Software in Linux Without Using Any Package Manager

| Comments

Package managers are awesome. As awesome as automatic software installation get you. Would it be apt, yum or pacman, they are all awesome for their systems. But sometimes we need to install binaries. Your package manager knows how to install a .deb or .rpm, but what about the stuff in that ./bin folder of the tar.bz2 bundle of latest version of your favorite software you just downloaded? No, it can’t be handled with the package manager.         

Why installing binaries?

Why would I need to use binaries you say!? Yea you are right, packaged software from the repositories of your trustworthy GNU/Linux distro is well tested and all, but sometime it’s not enough. Here are some reasons you might consider good enough for occasionally using binaries.                   
  • Software in repositories are not always up-to-date (you know better Ubuntu users)                                                                   
  • Some super awesome software is not available form repositories                                                                                      
  • You have compiled something yourself and you wanna use it as an installed software now                                                              
  • You have built a software/script yourself and want to use it directly from command line                                                             
        etc etc. There are many.

How to execute binaries?

I know you all know this, but let’s not leave the new guy behind. In Linux, when you have got a binary file (you can download latest firefox package for linux for an example), you need to first make it executable.
Try the following command for that.
      chmod +x /path/to/binary/file
This should be enough. You can now execute the binary by simply double clicking it, or from the terminal with just write it’s path in terminal and pressing enter.

So what’s the fuss?

Yea, it’s that simple to execute a binary. But wouldn’t it be better if we would not need to write the whole path to the file everytime we need to execute it? Wouldn’t it be sweet if we could just use it like any other command from the terminal, like ‘cd’? Yes I know it’ll be awesome. 

How to directly install binaries in Linux

There are many ways to do this. We’ll touch here some of them (enough of them that you’ll be able to install binaries on any Linux distro, would it be Ubuntu, Fedora, Arch or whatever). Let’s precede with the simplest of them. 

Creating a symlink in the $PATH

We need some explanation here (I suppose). What is a symlink? What is $PATH?                                                                        
Well, symlink is thing you call ‘shortcut’ in windows. It’s a symbolic link (shortcut) to some file or folder. 

And $PATH? It’s a list of all the directories (folders) in which our Linux system search for commands. Any executable file placed in any of the folders included in $PATH is treated as a command and can be directly executed from terminal. You can see what’s in $PATH on your system with this: 
        echo $PATH
So what we are gonna do is create a symlink of our binary file and place it in one of the folders in $PATH. That should be enough to make it a command in itself.                                                                                                                                  
        ln -s /path/to/file            
 Above is the command to create a symlink. It will create the symlink and place it in the $HOME (that’s your home folder). You can then move the link from there and place it in one of the folders in $PATH.

Let’s do it with an example. Assuming we have the firefox extracted in a folder and located on system somewhere like:                               
Following command will create a symlink to our binary.
        ln -s /media/F/Setups/Linux/Web/Firefox/firefox
It should create a file called ‘firefox’ in our file folder. Remember, this is not same as copying the file, it’s creating a symbolic link (shortcut). You can verify this with following command:
        file ~/firefox
It’s output should be like:
firefox: symbolic link to `/media/F/Setups/Linux/Web/Firefox/firefox’

Then move this file to somewhere in $PATH. You’ll need to use ‘sudo’ for that as most of the folders in $PATH are not writable for ordinary users.  
        sudo mv ~/firefox /usr/local/bin
WARNING: Do not create symlink with ‘sudo’

Adding the folder to $PATH

In previous method we saw to create a command (a.k.a installed binary) by placing the symlink in a folder which was already in $PATH. But we can do it the other way. We can add the folder containing our binary to the $PATH itself.
Here’s the command to do that for one terminal session.
        export PATH=”/path/to/binary/folder:$PATH”

Don’t forget to replace ‘/path/to/binary/folder’ with the path to the folder that’s containing your binary file.                                    
But this works only for current terminal session. As long as the terminal is closed, system will forget there’s a command as your binary. To make it work in all terminal sessions everytime, you’ll need to copy above command and place it in your ‘~/.bashrc’ or ‘~/.profile’ file (just put it in the end of either of the above files).                                                                                                              

Using update-alternatives command [RECOMMENDED]

Well, this is a post for Linux newbies, so I assume you are using some variant of Ubuntu. Ubuntu (may be other Debian based system and may be Fedora as well) have a very useful command ‘update-alternatives’ that let you install alternative versions of different software and to easily configure which one you want to use.
As in our example case, you might have firefox already installed and re-installing the binary will do nothing but confuse the system (although it’ll not get confused, but you will).

Syntax for using above mentioned command is easy and straight forward. Consider taking a look at ’man update-alternatives’ or at least ’update-alternatives –help’.

What ‘update-alternatives’ actually do is similar to what we did in method 1. It creates a symlink to our binary file and automatically place in a folder on $PATH (we need to tell which one). But what it do extra is, make the command available to all users and keep a record of which one of many executables you gonna install under same will be available from command line.
Here’s the quick example for our use case, i.e. installing a binary.
Let’s assume we already have firefox installed in the system, but we want to install firefox-nightly under same name (firefox that is) and switch between two whenever we want.
Use following command:
sudo update-alternatives –install /usr/local/bin firefox /path/to/firefox-nightly 1

Here’s the quick illustration of what’s going on in above command:
        sudo – You need to be ‘root’ to use this command, so sudo
        update-alternatives – It’s the command itself
        –install – It tells what action should be taken for updating alternative software. Here we wanna install new one.
        /usr/local/bin – It’s the folder in which we want to create the symlink. It must be in the $PATH.
        firefox – It’s the name under which you want to install the executable.
        /path/to/firefox-nightly – It’s the path to the file which should execute on running above named command
        1 – It’s the priority that should be given to the command we are installing out of other commands with same name already present on our system.    
We now have two versions of firefox. The one which was already present and the nightly build we installed afterwards. Following command can be used whenever we want to make a switch between the software that should be run by ‘firefox’ command (i.e stable or nightly or whatever):                 
        update-alternatives –config firefox
It’ll give a list of the firefox versions installed and you can choose whichever you want to use.                                                                                                                                                                                                                
I am sure there’ll be other ways of installing binaries as well (this is GNU/Linux after all), but these are the ones I use most often (and that are on my mind right now). If you know other better ways, please do inform me, or if I am doing something wrong here or you want me to explain something better, please mention in comments.

Circle Beat Of The Geek on Google Plus
OR Like us on Facebook  OR Follow on Twitter