Location of binary files during manual installation in Linux based operating system.
Today, I am going to talk about the location of binary files in ubuntu,linux based OS. Knowing the location of binary files in ubuntu is very important as it develops the basic understanding of manual installation of software in linux based OS.
When we do manual installation,it is very necessary to know where all the files are getting installed, how OS is accessing the installed program or how the program is installed for multiple user or for single user or for administrator use.
The various locations of binary files are as follows:
- /bin
- /usr/bin
- /usr/local/bin
- /sbin
- /usr/sbin
- /usr/local/sbin
- /opt/package-name/
Now one question arises... why so many different locations for storing binary files?
Each location has different purposes as we will see below.One more thing when I say binaries I mean executables.
1. /bin directory:
It contains essential command binaries.
The commands which we use such as cat,cp,chmod,chown,mkdir all are located in this /bin folder
It may also contain commands which are used indirectly by scripts and may also contain symbolic links to commands.Example of symbolic links from my Ubuntu12.10 OS is netcat,mt.
There must be no subdirectories in /bin
Who can run the command binaries????
Ans: Users as well as Administrator
2. /sbin directory:
It contains binaries essential for booting,restoring,recovering,and/or repairing the system.Example of binaries which are placed in /sbin are fdisk,reboot,halt,init.
In this case also you won't find any subdirectories in /sbin
Who can run the binaries????
Ans: Users and Administrators.
This directory contain utilities used for system administration and other root-only commands.
Difference between /bin and /sbin directory???
Basically the executables are divided into two categories.
1.Executables which are used for general purpose such as
- cp for copying purpose
- mkdir for creating directories
- chmod for changing the mode of file to execute(+x)
- fdisk:which can manipulate the partitions.
- mkfs: command which is used to build filesystem.
- ifconfig: which can be used to change the configuration of network cards(interface)
3. /usr/bin directory:
It contains binaries for default application that comes with the distribution.Example includes
- apt-get :which comes as a default application in ubuntu to install programs.
- avconv:which comes as a default application in ubuntu for converting video or audio formats.
When you install applications from Ubuntu Software Center,their binaries also goes into /usr/bin directory. There is one very important distinction between /usr/bin directory executables and /usr/local/bin directory executables which I will discuss after few minutes.
4. /usr/local/bin directory:
It contain binaries of the programs that are installed outside of the normal distribution.
Suppose if you download any application as tar.gz and installed it in Linux based OS you will see its executables in /usr/local/bin directory.
Now the question is why the executables of manually downloaded programs are found in /usr/local/bin directory and why not found in /urs/bin directory????
Ans:
It solves system update problem.
Running with a heavily customized applications can make using a computer a more pleasant,and often more productive task.
The FHS defines the /usr/local as the "tertiary hierarchy for local data installed by the system administrator". Means put apps you build yourself here.
Using the /usr/local folder as the destination when compiling and installing command-line software(such as Ruby,Rails,wget,Apache,django,python,etc) is critical for many reasons.
Mac OS X,Windows,commercial Unix systems,and Linux distributions all make use of software updates to deliver newer versions of their software to their users.
This process involves an automatic or manual process where the operating system checks for an update from the mothership, and then downloads and installs the update,which usually consists of newer version of applications,bugfixes,files,etc.
These new components are often moved into place with brute force regardless of what was there before.It's possible that you have made any customizations to the manually downloaded file or system files or binaries.All the customization will be overwritten at will by the software update if placed in /usr/bin directory.... but if these files are placed in their safe haven,i.e /usr/local, the update will not touch this location.
Summary: When we update our linux based system,it will not update the files which are placed in /urs/local directory.But it can update the files which are present in /usr/bin directory. Hence placing the customized applications in /urs/local is safer and necessary as well.Hence /usr/local/bin contain binaries or symlink of the manually installed applications.
5. /usr/sbin:
System administration programs(binary executables) which are provided by the distribution and can be updated by package manager.
6. /usr/local/sbin:
System administration programs(binary executables) that are installed outside of normal distribution and cannot be updated by package manager.
7. /opt/package-name:
You can even place your third party applications that don't rely on any dependencies outside the scope of said package in /opt/ directory also. But simultaneously you need to set the path of the executable which comes with your application in $PATH variable or you need to create the symlink of the executable in your /usr/local/bin directory.
Lets learn about /usr directory and /usr/local
/usr directory
/usr is the second major section of the filesystem. /usr is shareable,read-only data.That means various FHS-compliant hosts can share /usr over the network but cannot write anything onto it.
The following directories, or symbolic links to directories, are required in /usr.
/usr/local : Local hierarchy
Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr.
The following directories, or symbolic links to directories, must be in /usr/local
Now the question comes who can access the programs installed in /usr or in /usr/local ???
Ans: All the users as well as the administrator of the single system can access the installed program. If you want user specific programs you can install inside the /home/yourdir .
References:
Thank you for your post, I now better understand the maze of ubuntu directories,
ReplyDeleteand especially the critical difference between usr/bin and usr/local/bin :)
Have a nice day!
Thanks mate...It makes me feel good that atleast this post is useful to someone...
Delete