Tuesday, March 7, 2017

Mac OSX Set Edit PATH Variable

If you are using MAC OSX for development for say android, Laravel, Sencha , Java, Composer then you must have faced this issue. There are SDKs for this development and it's installed some where in your disk and it has certain executable which you can use on command line. For example to create laravel application on your disk you can go to terminal and go to place where you want to create your application and type following command.

laravel new MyApp

But most of the time you get an error command not found. Same with the other development. So if you are using OSX and get command not found error on your terminal, that means you have to set PATH of that command to your PATH variable in OSX. In this blog I am going to mention how to do this.

$PATH variable is very similar to environment variable on windows. Once you add path of command to $PATH variable, you can execute that command from anywhere in terminal. If you want to see what is current values in your $PATH variable. You can go to terminal and type following command.

echo $PATH

and it will show you current values stored in your path. Easy and best way to set value in $PATH variable is through bash_profile file. On OSX each user will have bash_profile file that has this $PATH variables stored. Here you can append new PATH to your SDK to execute certain command. For that first of all open bash_profile file. Go to terminal and type following command.

nano ~/.bash_profile

It will open your bash_profile file. It will look something like this.



Here go to end of the file and add your new PATH here. For that first of you have to find out absolute path of command on your disk. For example in case of laravel. SDK is stored at path

/Users/hirendave/.composer/vendor/bin

Same way for your command and SDK you have to find out the exact path and add it $PATH variable. Go to end of the file and add path. For example for laravel.

export PATH=/Users/hirendave/.composer/vendor/bin:$PATH

Here we are just appending new value to existing values. To save this click

control + X

It will show below message.


Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?  

Type Y here and hit enter. It will confirm from you to save changes to .bash_profile file. Hit enter again and it will close the file and take you back to terminal. Now close all the terminal and launch it again and type the command it will surely work.

So for all the command you want to use on terminal, you can use this trick to save path in $PATH variable to that can be used from anywhere in terminal.

No comments:

Post a Comment