Very basic information that every Linux user needs to know - How to export $PATH . This variable contains all the paths which may have executables that will be recognized throughout the System. For example lets say you installed java. You want to compile a program and so you do javac TestClass.java and you get javac is not a recognized command. One way to resolve this is to do pathtojdk/bin/javac TestClass.java but this is not the best way. You can add path pathtojdk/bin to that $PATH environment variable and then you can access all commands in bin folder from anywhere in your System. So lets see how can we achieve this...
So lets say I want to add following 3 paths to $PATH env variable
then again you can check the $PATH variable using echo.
But wait a second. Restart the console and if you notice the exported PATH is gone. Yes it is lasts only for that console session. So lets see how can we export this $PATH permanently.
- Edit your ~/.bashrc file and add the export line there.
- Save the file.
- Lastly execute source ~/.bashrc
and thats it. Those PATHS should be in your $PATH environment variable permanently from there on.
- It's often considered a security hole to leave a trailing colon at the end of your bash PATH because it makes it so that bash looks in the current directory if it can't find the executable it's looking for.
- Consider the scenario when you unpack a tarball, then
cdto the directory you unpacked it in, then run
ls---and then realize that the tarball had a malicious program called
- There can be other, more nasty versions. For instance, creating a malicious script called
sland waiting for someone to mistype