I am wanting to create a file in Solaris, so that I can export a few "items" whenever the machine is started up.


I want to export ORACLE_HOME and ORACLE_SID and some other directories, of my own, when the machine has started up.

These are the 2 Oracle folders I need to export:

export ORACLE_HOME=/oracle/product/11.1.0/db_1/
export ORACLE_SID=orcl

This is the other folder I need to export of my own:

export TESTFOLDER_DIR=/test/testfolder/bin/

It is highly irritating that I have to do it every time the machine has started up.

I have tried Googling it, but I have not seen anything yet (still searching). It is easy to make the file with the export commands, but to put it somewhere that the machine will know to use them in startup, is the issue.

Is there a way I could do it?


If these variables need to be set for every account, the simpler would be to add the export statements to /etc/profile. This file is not root's profile but a file sourced for every account using an interactive Bourne shell family shell (sh, ksh, bash, ...)

You can then just add at the end of this file.

export ORACLE_HOME=/oracle/product/11.1.0/db_1/
export ORACLE_SID=orcl
export TESTFOLDER_DIR=/test/testfolder/bin/

Otherwise, just add these three lines in your shell startup file (likely one of $HOME/.profile or $HOME/.bash_profile).

If you are logging in as root (which is not a good practice), that would be /.profile or /root/.profile

Finally, should you want to unconditionally set these variables whatever the shell is used and even for non interactive login stuff, like services, you can use the /etc/default/init file. Note that the export builtin is not required in this file as it is not a real shell script but really a configuration file, eg:

| improve this answer | |
  • Thanks for that. I have found export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC in the /etc/profile file. DO I put them in there? This is the root's profile. – Kevdog777 Feb 26 '13 at 9:54
  • Root profile is either /.profile or /root/.profile. Answer updated to clarify. – jlliagre Feb 26 '13 at 10:05
  • /etc/profile only applies to interactive logins, not to system services. For completeness, how can you define environment variables that also apply to services started by init under Solaris? – Gilles 'SO- stop being evil' Feb 26 '13 at 22:45
  • @Gilles Answer updated with the supported method to define these kind of variables. – jlliagre Feb 26 '13 at 23:01

In Solaris 11 /etc/default/init contains the following statement:

# READERS OF THIS FILE: This file is Obsolete.  Migrate to reading properties from svc:/system/environment:init.

So system wide environment variables can and should be set using the SMF utility and configuring the appropriate service in an appropriate way.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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