Ajout de variable d'environnement sous Linux

De PedroWiki

Introduction

Cet article est rédigé dans le cadre de l'installation d'un portail ESUP.

Il peut être utile pour tous les cas de figures nécessitant l'instanciation de variables d'environnement Java.

Les variables JAVA_HOME et ANT_HOME prise en exemple sont à instancier sur tous serveurs portant un serveur d'application java (Tomcat).

Méthode

Exemple sous Ubuntu 7.10

JAVA
root@ubuntu:/var/www# ls -la /etc/alternatives/java
lrwxrwxrwx 1 root root 40 2008-04-24 14:27 /etc/alternatives/java -> /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
root@ubuntu:/var/www# export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/jre

ANT
root@ubuntu:/var/www# which ant
/usr/bin/ant
root@ubuntu:/var/www# ls -la /usr/bin/ant
lrwxrwxrwx 1 root root 20 2008-04-24 15:56 /usr/bin/ant -> ../share/ant/bin/ant
root@ubuntu:/var/www# export ANT_HOME=/usr/share/ant

rc.local (après modification)
root@ubuntu:/var/www# more /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/jre
export ANT_HOME=/usr/share/ant

exit 0
root@ubuntu:/var/www#

/etc/profile
(...)
umask 022

export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/jre
export ANT_HOME=/usr/share/ant
(...)

Exemple sous Fedora Core 6

JAVA
[root@localhost]# ls -la /etc/alternatives/java
lrwxrwxrwx 1 root root 30 avr 24 15:46 /etc/alternatives/java -> /usr/java/jdk1.6.0_06/bin/java
[root@localhost]# export JAVA_HOME=/usr/java/jdk1.6.0_06

ANT
[root@localhost]# which ant
/usr/bin/ant
[root@localhost]# ls -la /usr/bin/ant
-rwxr-xr-x 1 root root 9352 aoû 30  2006 /usr/bin/ant
[root@localhost]# export ANT_HOME=/usr

rc.local (après modification)
[root@localhost]# more /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
export JAVA_HOME=/usr/java/jdk1.6.0_06
export ANT_HOME=/usr

[root@localhost]#

/etc/profile
(...)

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

export JAVA_HOME=/usr/java/jdk1.6.0_06
export ANT_HOME=/usr/share/ant
(...)[[Category:Linux