I use Ubuntu 14.10 with bash shell.
I downloaded a gradle
distribution and moved it to a new directory.
I want to permanently set a environment variable to point to the bin
sub-directory of the gradle folder.
I have edited ~/.bashrc
and ~./profile
according to recommendations to include the path to the gradle's running script. Yet when I type gradle
(which is the name of the script in the bin folder) it does not run.
Logged out, rebooted and everything but still it does not work.
Is there something I am missing here?
-
added this line on the end of
.bashrc
export GRADLE=/home/sanctus/Documents/Development/gradle-2.2/bin
-
My
~/.profile
file's contents are these:# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$HOME/sanctus/Documents/Development/gradle-2.2/bin" fi gradle="$HOME/sanctus/Documents/Development/gradle-2.2/bin" export gradle
Best Answer
First of all, you don't want to do
gradle="..."
. That simply creates a variable calledgradle
and is irrelevant (unless that variable is somehow used bygradle
but you haven't said so). What you want to do is add the directory containing thegradle
executable to the list of directories your system searches through when trying to find programs to run. This is what thePATH
variable does.It is also important not to overwrite the existing contents of
PATH
. So, to addfoo
to thePATH
, you do:And not
The latter will remove everything from
PATH
and replace it withfoo
alone.So, combining all this, you want to add the following lines to your
~/.profile
(or~/.bash_profile
if that exists, but not to your~/.bashrc
):Why
~/.profile
or~/.bash_profile
and not~/.bashrc
? First of all, because that's what profile is for. More importantly,~/.bashrc
is read each time you start a new shell. So, for example, each time you open a new terminal. Setting environmental variables that only need to be set once in that file, makes them be reset each time you open a terminal and that's just needless overhead.Additionally, settings in
~/.bashrc
only affect programs launched from the commandline. If you launch something using the GUI ( a menu entry or a.desktop
file, for example) those variables will not be available there.In many systems, including Ubuntu,
~/.profile
is read when you log in graphically. Variables set in that file will therefore be available to GUI programs as well. Also, setting these variables in~/.profile
is preferred since that file is only read once: at login.Additionally, this will work even if you change your shell to something other than bash, since
~/.profile
is read by many of the most popular shells.Important : If a
~/.bash_profile
exists, that will be read instead of~/.profile
. So, if you do have such a file, use that one instead. My recommendation is, if you have a~/.bash_profile
, to simply delete it and add anything that was there to your standard~/.profile
.