File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Setting environment variable in Ubuntu 10.4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply locked New topic
Author

Setting environment variable in Ubuntu 10.4

Nikes Shah
Ranch Hand

Joined: Jul 18, 2007
Posts: 133
Hi All,

I am new to Linux flavor systems.

Can anyone guide in which file we can set environment variable?
Is there any UI available like windows for environment variable setup?

I have an ant script which expects a path defined in environment variable.

Thanks

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

There are many - perhaps too many - places to set environment variables. Environment variables are part of the environment component of the command shell, and Linux has probably half a dozen major shells to choose from, with bash being the most popular, but also csh, ksh, zsh, and others being used as well.

The closes thing to the "system" environment in Windows is probably /etc/profile, which is a reference for all the major shells. Each shell generally maintains one or more profiles unique to that shell - for example ".bash_profile", which is a file in the user's home directory used to setup the environment for the bash shell. User-specific profiles are are "hidden" files, and the user-specific version of /etc/profile is "~/.profile", where "~" is the shorthand for the user's home directory as implemented in most popular shells.

When a shell or the desktop spawns a sub-shell, the spawning process has the option to propagate a copy of the parent shell to the sub-shell or to create a new, empty environment, Likewise, the spawning shell can request that the user's login script be executed or ignored, and the login script is what sets the user's initial environment at login.

All of this can get pretty complicated, but for basic purposes, you probably want an entry in the ~/.profile file such as this:



Depending on the shell, you may need to do the export as a separate command after you set the value. You must export the environment variable or it will only be in effect for the current shell.


Customer surveys are for companies who didn't pay proper attention to begin with.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hi Tim,

I was following the below instructions for Ubuntu 11.10

Hi,
I was following these instructions :

The ~/.bash_profile ($HOME/.bash_profile) or ~/.prfile file is executed when you login using console or remotely using ssh. Type the following command to edit ~/.bash_profile file, enter:
$ vi ~/.bash_proflle

Append the $PATH settings, enter:
export PATH=${PATH}:${HOME}/bin

Save and close the file.



I entered the first command vi~/.bash_profile on the terminal and pressed ENTER.
The terminal now shows a blank screen with ~ at the beginning of every line & ~/.bash_profile [New File] at the bottom.
Now if i try to write anything then nothing appears in the terminal while the bottom line shows 'Nothing to register'.

Is there a way to open such file in Notepad and then append the line ?

Please advise.


Thanks,
Pramod
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5842
    
    7

pramod, please to not ask the same question in multiple posts.
http://www.coderanch.com/t/563245/Linux-UNIX/Setting-PATH-Ubuntu#2557280


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting environment variable in Ubuntu 10.4