7

I'm using a program called node-webkit, but I can't start the program without specifying the full path to the executable file. Is there any way to associate a command (such as node-webkit) with an executable file on Linux, so that the full path to the file won't need to be specified?

5

A third option, perhaps least intrusive, is to add an alias in your .bashrc file. This file is a set of options for bash which it reads every time an instance of bash is started.

  • Open your .bashrc file with your file editor, for e.g gedit ~/.bashrc

  • Add the below line to the bottom of your .bashrc file
    alias node-webkit=/path/to/node-webkit

  • Do source ~/.bashrc to be able to use the alias as if it were a command.

The way this works is like #define in C/C++, when you type node-webkit, it will be replaced with the right hand side of the alias definition, which here is the full path to the executable.

  • .bashrc is not always read when bash is executed, it will only be read by a.) interactive shells, and b.) non-login shells. .bashrc should be sourced from .bash_profile to work around the latter. – Chris Down Dec 12 '12 at 22:22
8

In order for the binary to be executed with it's name alone, the directory containing the binary needs to be in one of the directories specified by your PATH environment variable. You can add the directory the binary is currently in to your PATH with the following:

export PATH="/new/path:$PATH"

You can place this in an initialization script for your shell, ~/.bashrc for example. When it is a single command, I typically symlink the binary to location already in my PATH.

ln -s /path/to/node-webkit /usr/local/bin
3

Sure ... symbolic links. The command is "ln".

me@computer:~> echo $PATH
/usr/lib/mpi/gcc/openmpi/bin:/opt/lsb-tet3-lite/bin:/opt/lsb/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin

This is your path variable. Say, you have root privileges, creating a symlink into /usr/bin makes sense:

cd /usr/bin
ln -s /path/to/your/program/node-webkit node-webkit
  • 2
    This doesn't really answer the question. eg - symlink where? – jordanm Dec 5 '12 at 0:55
  • Any location, which is already within your path. I assumed, you do not want to change your path variable. – s-m-e Dec 5 '12 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.