LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   setting path and classpath (https://www.linuxquestions.org/questions/linux-newbie-8/setting-path-and-classpath-567827/)

Raakh 07-09-2007 09:40 AM

setting path and classpath
 
I am setting path like:
export JAVA_HOME=/usr/java/jdk1.6.0_01/bin
export PATH=$JAVA_HOME;$PATH

but when am relogging then I have to reset path again. how can i set the path or classpath permanently

thanks & best regards

timmeke 07-09-2007 09:48 AM

What shell are you using? Bash?

If so, you should add those lines to ${HOME}/.bash_profile or ${HOME}/.bashrc

If you want other users to also benefit from these settings, add them to /etc/bashrc or /etc/profile instead (requires root access).

Raakh 07-09-2007 10:07 AM

Quote:

Originally Posted by timmeke
What shell are you using? Bash?

If so, you should add those lines to ${HOME}/.bash_profile or ${HOME}/.bashrc

If you want other users to also benefit from these settings, add them to /etc/bashrc or /etc/profile instead (requires root access).


[root@bhinternationalltd etc]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin://sbin://bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@bhinternationalltd etc]# ${HOME}/.bash_profile
-bash: /root/.bash_profile: Permission denied
[root@bhinternationalltd etc]# ${HOME}/.bashrc
-bash: /root/.bashrc: Permission denied
[root@bhinternationalltd etc]# ${HOME}/etc/bashrc
-bash: /root/etc/bashrc: No such file or directory
[root@bhinternationalltd etc]#

Raakh 07-09-2007 11:18 AM

Quote:

Originally Posted by Raakh
[root@bhinternationalltd etc]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin://sbin://bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
[root@bhinternationalltd etc]# ${HOME}/.bash_profile
-bash: /root/.bash_profile: Permission denied
[root@bhinternationalltd etc]# ${HOME}/.bashrc
-bash: /root/.bashrc: Permission denied
[root@bhinternationalltd etc]# ${HOME}/etc/bashrc
-bash: /root/etc/bashrc: No such file or directory
[root@bhinternationalltd etc]#


Why permission denied message appear and how can I remove it

timmeke 07-10-2007 01:39 AM

I was telling you to edit the .bash_profile file in your user's home directory.
So ${HOME}/.bash_profile and ${HOME}/.bashrc are OK as paths if you want to run them, but you should open
them in an editor instead.

${HOME}/etc/bashrc is an invalid path: ${HOME} variable contains your home directory (ie /home/user or /root for the root user), but this directory probably does not have a subdirectory called "etc". Instead, you need /etc/bashrc (absolute path, not relative to ${HOME}). To see what $HOME contains, just echo it:
Code:

echo ${HOME}
Finally, executing a bash_profile or bashrc file is no good, as the environment settings made by the commands inside the files are undone once the execution is completed. Instead, you need to "source" the files, using the "source" or "." commands, as in the following examples:
Code:

. ${HOME}/.bashrc
source ${HOME}/.bash_profile

As for the permission denied issue. Most likely, the files are not set to be executed (x permission). You can check this by executing
Code:

ls -l ${HOME}/.bashrc ${HOME}/.bash_profile
or similar for the files in /etc.


All times are GMT -5. The time now is 12:17 PM.