Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to set up Apache Tomcat on my pc, and it wants me to set up an environment variable for CATALINA_HOME. Does any know how to do this?

share|improve this question

4 Answers 4

up vote 26 down vote accepted

In bash you can set variables like this:

export CATALINA_HOME=/opt/catalina

most other shells follow this convention, but not all. You can set it permanently in ~/.profile for bash (and as before, other shells have other locations)

share|improve this answer
3  
for session-wide variables, help.ubuntu.com recommends ~/.profile as probably the best file for placing environment variable assignments in, since it gets executed automatically by the DisplayManager during the startup process desktop session as well as by the login shell when one logs-in from the textual console. –  McDowell Aug 4 '10 at 21:49
    
Updated the answer. The reason why i used .bashrc instead was that at some point .profile wasn't sourced automatically. But if it works now, it's better to use it. –  Ressu Aug 5 '10 at 5:07
    
Setting it in ~/.profile doesn't work for me. It works in ~/.bashrc though. –  jumpnett Aug 7 '10 at 0:56
    
Setting it in ~/.bash_profile works as well. –  jumpnett Jan 31 '13 at 0:45

Environment variables should already work

If you are using the tomcat6 package from the Ubuntu repositories, then the CATALINA_HOME and other environment variables are already set, in the /etc/init.d/tomcat6 startup script.

If you are installing tomcat outside the package manager (hopefully in /opt or somewhere else outside the managed file system), then running the TOMCAT/bin/startup.sh should use the relative location to define the CATALINA_HOME.

Setting the Environment variable

If for some reason you still need to set an environment variable you can open a terminal window and type in the command:

export CATALINA_HOME=/path/to/the/root/folder/of/tomcat

This environment variable will now work within that terminal window, but if you open another window or logout/login you loose that setting.

Make the environment variable permanent

To make the environment variable setting permanent, there are several places you can define the setting.

To be really sure the setting is being picked up, add the above setting to one of the startup script for tomcat:

yourtomcatfolder/bin/startup.sh

yourtomcatfolder/bin/catalina.sh

Note: startup.sh calls the catalina.sh. You should add the setting at the start of one of these files (after any initial comments)

The standard way for global environment variables would be to add an entry in /etc/environment (you do not use the command export in this file as it is not a normal bash script)

CATALINA_HOME=/path/to/the/root/folder/of/tomcat

Not recommended

You can set the environment variables in the bash (command line shell) configuration files, but these are not recommended as they are not always picked up (eg. if you are running a server that you dont login to to run tomcat): ~/.bashrc | ~/.profile | /etc.bash.bashrc | /etc/profile

share|improve this answer
2  
It should not be the startup or catalina scripts, but the setenv.sh or setenv.bat script, creating it if needed: "Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can be specified in the "setenv" script. The script is placed either into CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be readable." (Running The Apache Tomcat 7.0 Servlet/JSP Container, Section 3.4) –  Olathe Oct 5 '13 at 0:53

The best place for this depends on how and where you've installed Tomcat, what applications you want to pick up this setting and how global you want the scope to be.

The Ubuntu documentation on Environment Variables discusses the pros and cons of the various options.

share|improve this answer
    
What are you referring to when you say, "best place for this"? –  jumpnett Aug 3 '10 at 22:58
    
@jumpnett - I mean where to make the setting persistent so that it is always available to the applications depending on it. Unless you're happy typing the setting in every time or want to write your own script. –  McDowell Aug 4 '10 at 21:44

After going through Ubuntu Documentation on Environment Variables, I came up with following workaround:

##Save & run the following in a shell script,

export ENVIRON_VAR_NAME = Value<br/>
any other initializations like<br/>
export PATH = $PWD:$PATH<br/>
bash

The last line creates a child shell, which inherits Environment Variable values from parent shell (which have just been set).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.