DonaldLouch Linux uses the PATH variable to identify where programs are. This allows you to specify programs like composer
without specifying its full path
This doesn't stop you from using the full path of course. You can call it from its absolute location, but you cannot call it directly, eg $ my_script
but you can with another program (as you did with php composer.phar
. A shortcut is often ./program_name
. the .
defines the Current working directory (with ..
going "up" one in the tree).
However, if you prefer the luxury of simply typing composer command
and do not have permissions to alter protected directories, you can define the PATH variable to include your directory.
If you examine this link
https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path
You will come across this answer:
Either way works, but they don't do the same thing: the elements of PATHare checked left to right. In your first example, executables in ~/opt/bin will have precedence over those installed, for example, in /usr/bin, which may or may not be what you want.
DonaldLouch So I've been trying to install the updated version of Composer and it seems as the version of Composer in the bin cannot be overrided. The version in the bin is on version 1.1.1 whereas the other "local" versions has been updated to version 1.2.1 but I'm still not reciving the update.
You don't specify what you did to have your updated version to have preference of the system version of composer, however you can try this sequence of commands to have PATH prefer programs in /home/$USER/bin
rather then other locations in the system.
# These are untested commands
mkdir ~/bin
export PATH=~/bin:$PATH
php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php composer-setup.php --install-dir=~/ --filename composer
php -r "unlink('composer-setup.php');"
composer selfupdate
Note this will only be effective for the current session. If you want your PATH environment variable to "remember" this change, it will have to be set everytime. You can do this by placing it in ~/.profile
eg
echo "export PATH=~/bin:$PATH" >> ~/.profile
Also, be aware this exposes you to a increased risk of being hacked. Should somebody malicious place a binary file called ls
, it would be called over /bin/ls
For educational reference here is PATH from the manual page (man bash
) of bash
PATH The search path for commands. It is a colon-separated list of
directories in which the shell looks for commands (see COMMAND
EXECUTION below). A zero-length (null) directory name in the
value of PATH indicates the current directory. A null directory
name may appear as two adjacent colons, or as an initial or
trailing colon. The default path is system-dependent, and is
set by the administrator who installs bash. A common value is
``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:
/sbin''.