One thing you can do is have everything in you bashrc or bash_profile and comment and uncomment the required environment variables. Believe me, I did that for a long time. duh...
Or else, you can have scripts to set your environment !!! (yay). One sh file would look like this
#!/bin/sh
export JAVA_HOME=/home/isuru/installs/jdk/jdk1.8.0_101
export PATH=$JAVA_HOME/bin:$PATH
and the other would look like this
#!/bin/sh
export JAVA_HOME=/home/isuru/installs/jdk/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
But we can't memorize where this files are to locate them always. That's where alias comes in.
Create .bash_aliases file in your home directory. Check whether this file is being sourced inside your bashrc or bash_profile.
Add aliases to the ~/.bash_aliases as follows
alias java8='. /home/isuru/stuff/scripts/java8.sh'
alias java7='. /home/isuru/stuff/scripts/java7.sh'
In my machine both the script files are located under the directory /home/isuru/stuff/scripts. Make sure the sh files have execute permissions.
Now we are done here. Open a new shell and type in java8. and then java -version. Type in java7 and the java -version. See the magic :P
If you are following a routine everyday executing shell scripts, or some other stuff, put them in a single sh file and do register it as an alias. Will make your life easier.
If you are following a routine everyday executing shell scripts, or some other stuff, put them in a single sh file and do register it as an alias. Will make your life easier.
If opening a new terminal really hurts, you can source the ~/.bashrc or ~/.bash_profile file. You can stay where you are in the current terminal and yet get the benefits of alias. See below to uncover a secret ;)
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
When we open a new terminal the ~/.bashrc or ~/.bash_profile automatically sources :D :D
No comments :
Post a Comment