Somehow I managed to get rid of this problem by removing the previously set JDK_HOME in the profile and by re issuing the below command:
One more thing that I found was, I was doing the mistake of trying to launch IntelliJ from the root user. But later I found out that there was no JAVA_HOME set for the root user. But guys I have a question here. When we set the JAVA_HOME in /etc/profile, does it not hold good for all the users? I mean the profile is kind of system wide properties? Am I right?
With Ubuntu you should never log in as the root user, nor su to root. You should always log in with your own account and then use "sudo" to run commands that require root permission. And if you use sudo, your environment settings, such as JAVA_HOME, are kept.
Regarding which files bash reads on startup, it's a mystery to me. From the reading I have done, and by examining the .bashrc files, I cannot tell if bash reads certain files no matter what or if it only reads them because the ~/.bashrc file contains commands to read those files (and they in turn contain commands to read other files).