Linux: cómo hacer que un programa se ejecute desde cualquier sitio
Quiero abrir un terminal, teclear el nombre del programa y que se ejecute desde el sitio en que me encuentro dentro del árbol de archivos.
.¿Cómo lo hago?:
mkdir ~/.local/bin // Si no existe se creará. Es una carpeta oculta
chmod +x ~/Descargas/<programa> // Cambio de permisos a ejecutable
mv ~/Downloads/programa ~/.local/bin // Mover archivo
mkdir ~/.local/bin && chmod +x ~/Descargas/<programa> && mv ~/Descargas/<programa> ~/.local/bin
Si no funciona es porque la ruta no está indicada en el PATH de forma predeerminada.
Entonces hay que realizar lo siguiente:
$ sudo nano /home/dal/.bashrc
Al final del archivo agregar:
export PATH=$PATH:/home/dal/.local/bin/
En el proximo reinicio funcionará. Si lo necesitas ahora mismo, en la terminal ejecutas:
$ export PATH=$PATH:/home/dal/.local/bin/
y lo tendras solo por esta sesión.
Material de ref:
/.local/bin es un sitio predeterminado,( en los sistemas Linux ) en el que cualquier programa dentro de él prodrá abrirse desde cualquier sitio dentro del árbol de archivos.
https://appuals.com/how-to-make-a-program-executable-from-everywhere-in-linux/
Method 2: Create ~/.local/bin Directory
While the ~/.local/bin directory is actually included in most default PATH assignments, it tends to not actually get created on many popular GNU/Linux implementations. Unless you’ve created it because you were making a shell script or something else that you wanted to run from everywhere, then you probably don’t have it just yet. That being said, since it got added by default programs will run out of it straight away.
At the command prompt, type mkdir ~/.local/bin and push enter. You shouldn’t see any output. If you get an error message that reads something like “mkdir: cannot create directory “/home/user/.local/bin” with perhaps a different name than user, then you simply already have this directory. You can safely ignore the error message if this was the case, because all it tells you is that you already have a directory and bash isn’t going to let you put another one on top of it.
Now anytime you move something into that directory, you should be able to run it from anywhere. Let’s suppose you have a shell script called chkFile in your Downloads folder that you’ve first checked to make sure was safe and wasn’t going to cause you any trouble. Naturally, this is merely a made up file name and you’ll want to type ls ~/Downloads or what have you to find the actual name. Assuming our example was right, you’d need to type chmod +x ~/Downloads/chkFile to make it executable and then type mv ~/Downloads/chkFile ~/.local/bin to put it in the right directory. From then on out, you should be able to execute it from wherever it is.
