Sometimes there is a need to download some command-line application (like ExifTool) and run it from the Terminal, but without putting it into a main system directory for the bin files -
Since I’m not going to leave a bin file there for a long time, but instead I’m going to use it a couple of times and then delete it, then I would like to have a personal directory for temporary bin files instead of littering the main directory. This directory is also useful for putting your own script files there.
In this tutorial, you’ll learn how to create a personal bin directory at your home directory and run a command-line applications or your own scripts from this dirrectory without specifying their full path.
The following instruction is intended for macOS users.
If you use Linux, you may need to change some lines.
It will not work if you use Windows.
Launch the Terminal app from the Utilities folder of your Applications folder, or use Spotlight to find it.
In the Terminal window, type the following to browse to your home directory:
Check out if the
.bash_profile file exist in our user’s home directory.
... drwx------ 2 arthur staff 64 Feb 28 15:17 .Trash -rw------- 1 arthur staff 11793 Feb 12 20:24 .bash_history drwxr-xr-x 3 arthur staff 96 Jan 18 10:01 .bash_imb -rw-------@ 1 arthur staff 517 Feb 28 10:04 .bash_profile drwx------ 643 arthur staff 20576 Feb 28 10:03 .bash_sessions drwxr-xr-x 3 arthur staff 96 Oct 7 18:30 .bundle drwx------ 5 arthur staff 160 Jul 10 2017 .cache drwx------ 6 arthur staff 192 Jul 10 2017 .config ...
.bash_profile file doesn’t exist, we will create it with the following command:
Note! The name begins with a dot (
Open up our
.bash_profile file in the TextEdit application:
open -a TextEdit .bash_profile
Add the following line to the
PATHis marked for export by default, so we don’t need to use
~/is a shorthand for the user’s home directory, so we don’t need to set full path like so:
To apply the changes immediately to our bash profile without having to log out, we can run the following command:
Done. Now we can run a command-line applications or our own scripts from our personal bin directory that located in our user’s directory.
Let’s now try to test our new bin directory. For example, I will use the
Download the latest version of the
php-cs-fixer and rename file to
For this we can use
wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer
curl -L http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -o php-cs-fixer
Give the right to execution:
sudo chmod a+x php-cs-fixer
This command will promt us to enter our computer password.
Move file to our personal bin directory:
mv php-cs-fixer ~/bin/
Now we can confirm that we have the
php-cs-fixer tool available for use by using the
If this article helped you then please leave a comment.
Thanks for reading!