20

I have just recently installed Light Table downloading it from the git repository, and followed the instructions on this website to create a desktop launcher.

Now I want to run the program by directly typing in the terminal

LightTable

and not

./opt/LightTable/deploy/LightTable
2
  • 6
    @user68186 Adding the containing directory to the PATH environment variable is often not the best way to achieve this, and may sometimes even break the system or create security vulnerabilities. (One must consider any other executables that will be turned into commands from this, as well as where in PATH it's added.) Adding a shell alias, as covered by answers here, is better for anyone who doesn't want to consider such complexities; it is also more narrowly tailored to the specific app in question. Thus this is not a duplicate of that question, though they do overlap a little bit. Jul 21, 2014 at 23:20
  • Related (but not necessarily a duplicate): How do I add a directory to my path?
    – Seth
    Aug 25, 2014 at 2:47

6 Answers 6

25

This can be crudely accomplished with an alias. You can create a permanent bash alias by adding a single line to your .bashrc file.

In the terminal run nano ~/.bashrc

Add the the following line at the bottom:

alias LightTable='/full/path/opt/LightTable/deploy/LightTable'

notice I added thee full path instead of the . so this will work in any working directory. Close and reopen the terminal or run source ~/.bashrc to reload the bashrc file.

1
  • To run a command in the background, add & at the end: alias LightTable='/full/path/opt/LightTable/deploy/LightTable &'. To keep running the app after the shell is closed, add nohup at the beggining: alias LightTable='nohup /full/path/opt/LightTable/deploy/LightTable &.
    – Danijel
    Nov 13, 2020 at 13:37
8

This isn't an elementary question, the best way to do this is to make an alias, Ill use netbeans as an example

Open Terminal Ctrl+Alt+T

nano ~/.bashrc

write this at the bottom of the file:

alias netbeans='/home/john/netbeans-7.0.1/bin/netbeans'

Ctrl + x

Y

Enter

The netbeans word is the command you will use to start the program, you can change it to whatever you need. Inside the quotes is the command you want to run when netbeans alias is called.

In order this command to be active you have to re-open the Terminal

1
  • I cannot vote up due to my low reputation, but thank you for answering, it was very useful
    – dapias
    Jul 21, 2014 at 16:40
5

You can try to copy the executable to /usr/bin if its a simple executable program and doesn't depend on any other file. if it does depend of other files, the best to do is create a shortcut command to the program.

Where you create the alias is by yourself (.bashrc, .profile, etc). However I personally let all my enviroment variables in my .bash_aliases file (you need to create it at first stance).

Create the file .bash_aliases in your HOME folder and edit it anyway you like. Then to create the shortcut, you can do:

alias LightTable='path_to_opt/LightTable/deploy/LightTable'

Save the file and that's it.

ps: you can also put the alias as lighttable and LIGHTTABLE in case forget to uppercase the L or if capslock is active by accident, so you don't have to type the command again.

2
  • I cannot vote up due to my low reputation, but thank you for answering, it was very useful
    – dapias
    Jul 21, 2014 at 16:41
  • It's recommended to put things that aren't installed via Apt into /usr/local/bin instead. Things in /usr/bin can be erased or replaced by Apt packages, but things in /usr/local/bin are left alone. Jan 7, 2017 at 4:20
3

I'm not sure why other answerers have not suggested this, but as the OP actually pointed out, prepending to the $PATH variable would have been the way I would have achieved this:

echo 'PATH=/opt/LightTable/deploy:$PATH' >> ~/.bash_profile
source ~/.bash_profile

Then run with:

LightTable
1
  • Note: I would then alias LightTable to lighttable for ease of use: echo 'alias LightTable=lighttable' >> ~/.bash_alias && source ~/.bash_alias.
    – JoeNyland
    Jul 22, 2014 at 8:02
2

Better to create a symbolic link than an alias I think. An alias might make substitutions on your command line when you didn't want one; creating a symlink will allow you to run the program as you want:

sudo ln -s full_path_to_opt/LightTable/deploy/LightTable  /usr/local/bin

This will create a shortcut in /usr/local/bin (which should be in your PATH already!) to where LightTable actually is. Note also that you can rename the symlink as well if you don't like the capital letters in "LightTable":

sudo ln -s full_path_to_opt/LightTable/deploy/LightTable  /usr/local/bin/lighttable

Just for reference, if the program is awkwardly designed, i.e. complains about not finding configuration files or libraries or whatever, then another solution that might be more useful is creating a wrapper script. To do this just create a file (wherever you like for the time being) called "LightTable" (or whatever else you like) with this in it:

#!/bin/sh
# Simple script to run LightTable
if ! cd full_path_to_opt/LightTable/deploy/LightTable ; then
    echo "$0: error: LightTable directory not found." >&2
    exit 1
fi
exec ./LightTable

Change the permissions of this file:

chmod 755 <wrapper_script>

and try executing it just to see if it works, and if so then move it to /usr/local/bin:

sudo mv -i <wrapper_script> /usr/local/bin
4
  • What your saying is true, but didn't answer what he wanted. He wanted to execute it by using the name of the file/alias of the file
    – Johnn
    Jul 22, 2014 at 13:10
  • 1
    @Johnn: I'm sorry, I don't understand what the difference is. I understand the question as asking for a way to execute the program without having to specify its path. Whether the shell uses an alias or the PATH mechanism makes no difference if you are just asking to execute the program. If you wanted to do something else with the file then using an alias to provide the full path of the file is indeed the best way, but (s)he just wants to run the file. Am I mistaken?
    – Zorawar
    Jul 22, 2014 at 15:42
  • No that was my fault, your correct.
    – Johnn
    Jul 22, 2014 at 15:56
  • 1
    @Johnn: Ah, well, thanks for the critical eye anyway!
    – Zorawar
    Jul 22, 2014 at 16:16
0

I tried to do this , when I started in Ubuntu. When you put LightTable in terminal It searches for a file named LightTable in $PATH directories. you can put echo $PATH to get the directories.

If you want to execute your LightTable program in ./opt/LightTable/deploy/LightTable, then what you have to do is, place your Light Table file in /usr/games or /usr/bin. But that requires Super User Permissions

open the terminal by Ctrl+Alt+T

then put

I prefer to create a shortcut of LightTable using

sudo ln -s path/to/LightTable  /usr/games/LightTable

Then put the SU password. Then, you can access your program by using LightTable in the terminal

You can put /usr/bin or /usr/local/bin instead of /usr/games, anything that is a $PATH directory, It doesn't need to be like that, but I recommend you to place it in /usr/local/bin

I also recommend you to change the output file as lightpath instead of LightPath

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .