mcbetz
mcbetz

Reputation: 2389

How to make script executable on shell permanently?

I followed this answer to make a Python script, gn, in /opt/gn accessible via Terminal systemwide in Ubuntu like this:

PATH=${PATH}:/opt/gn

However, when I restart Terminal, I cannot longer execute the script system-wide. I have to retype the command from above.

I tried to copy that PATH to the last line of ~/.profile, but it would not work like that.

How to get permanent execution to a script?

Upvotes: 0

Views: 1614

Answers (2)

loentar
loentar

Reputation: 5249

In Ubuntu you can add additional search paths into /etc/environment. Just append your path at the end of PATH="..." adding colon before your path.

After that you must re-login or reboot.

Upvotes: 1

Fredrik Pihl
Fredrik Pihl

Reputation: 45670

To get it permanent you need to store the updated path to a file that is read by your shell at startup. Try adding the path to your .bashrc-file?

See the INVOCATION-section in the man-page for bash

The part that applies to your question is

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and exe‐ cutes commands from the first one that exists and is readable.

meaning that you simply put your updated path in the wrong file.

Upvotes: 0

Related Questions