How to make executable available everywhere in Linux (using ~/.bashrc)
Well, this is my programming log for future me who is very likely to forget what I have done today.
As a Linux newbie, I decided to get myself familiar with terminal. Not only does it look cool as a programmer, I believed it will improve productivity.
The first thing I have done is to find a text editor. I looked up options for nice and colorful editors available in terminal. I eventually found a light-weighted and color-supporting editor called “micro”. I decided to use it. It is an opensource(free) and well-documented. Those who are interested, check that out here https://micro-editor.github.io/
Anyway I installed micro at my home directory “/home/tofusoup429/mic ”.
The problem is that I had to type a long command-line, “/home/tofusoup429/mic/micro” to start the editor. This is extremely not cool and inconvenient. I wanted to start the editor by simply typing “micro” anywhere in my Linux shell.
I found a solution. I had to edit a hidden file named “.bashrc” in the home directory “home/tofusoup429” or “~”. It is hidden by default. So you can only see it by “ls -a”.
According to https://www.routerhosting.com/kb/what-is-linux-bashrc-and-how-to-use-it-full-guide/, “bashrc” is explained as follows.
“. bashrc is a shell script that Bash runs whenever it is started interactively. It initializes an interactive shell session. You can put any command in that file that you could type at the command prompt. … In order to load your preferences, bash runs the contents of the bashrc file at each launch.”
Open the “.bashrc” file and add path where the executable of the editor is located. The line I had to add was …
export PATH=“<PATH TO EXECUTABLE>:$PATH”
In my case the <PATH TO EXECUTABLE> is /home/tofusoup429/mic. Note that <PATH TO EXECUTABLE> should not include the executable itself.
It is basically me giving an order to linux that whenever I put a command, look up the path “/home/tofusoup429/mic”.
Then, you need to refresh “.bashrc”. You can either restart the terminal or simply source the bashrc file. I would rather source the file with command ~
Now it refreshes the .bashrc file and should reflect the newly added path.
It works. As soon as I put “micro” command, it opens the editor.
Thank you for reading my programming log. I hope this will save some time of other Linux newbies.