Translate

Tuesday 8 September 2015

How to add System Variable/Environment Variable in Mac OS

Following are the steps to set up the variable.

1. Open terminal.
2. Type the command ->  touch ~/.bash_profile -  The touch utility sets the modification and access times of files.  If any file does not exist, it is  created with default permissions
3. Type the command ->  open ~/.bash_profile - This will open the file.
4. Then you will see a file, it could be blank or you can see some variables already there. Now there are two things:
    a. You want to create a new variable all together  the format will be
         export VariableName=Path/Value to be set   (Please mind the spaces)

    b. You want to append the path, like in case of JAVA Path.the format will be.
         export existingVariableName=$existingVariableName:new value to be appended
     
         For instance export PATH=$PATH:/usr/bin/java

5. Now You save the document by pressing Command + S
6. Now type the command - source ./.bash_profile - This will save your changes.
7. To check the value of your system variable simply  write - echo $YourVariableName


Hope that this helps!!

Thanks!!