If you want custom Bash, NodeJS, PHP or any other script available as global bash commands you need to add them to the $PATH
environment variable.
- Create a new directory in your user's home directory that will contain global apps
- Install those apps to that directory and make them executable by the current user
- Add the directory to system's
$PATH
$[~/] mkdir ~/bin
$[~/] cd ~/bin
$[~/.bin/] curl -o composer https://getcomposer.org/composer.phar
$[~/.bin/] curl -o wp https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
$[~/.bin/] chmod u+x *
Then edit ~/.bashrc
and add in or edit the following line:
# Add custom directories to $PATH
PATH=$HOME/bin:$PATH
And source the new file (or open a new shell): source ~/.bashrc
You can now use composer
and wp
commands from anywhere on the system.
$[~/] wp --info
PHP binary: /usr/bin/php
PHP version: 7.2.7
...
For non-interactive shells (scripts connectng to server) to be able to use these commands the $PATH
needs to be set at the top of ~/.bashrc
, before the line that exits non-interactive shells.
# Add custom directories to $PATH
PATH=$HOME/bin:$PATH
[[ $- != *i* ]] && return
# rest of the file ...
- Install
nodejs
. Follow instructions on https://nodejs.org/en/download/package-manager/ - Create a new directory in your user's home directory that will contain global NPM packages
- Set NPM prefix to that directory
- Add the directory to
$PATH
Install Node with your distro's packet manager then:
$[~/] mkdir ~/node
$[~/] npm config set prefix ~/node
$[~/] npm config get prefix
/home/<user>/node
Then edit ~/.bashrc
and add the ~/node/bin
directory to $PATH
like so:
# Add custom directories to $PATH
PATH=$HOME/bin:$HOME/node/bin:$PATH
Source the new file (or open a new shell): source ~/.bashrc
If you've followed the instructions above, you should be able to install global NPM packages:
$[~/] npm install -g create-react-app
If you get permission errors, you did something wrong.