0

I know similar questions have been asked before on here (for example: How to add a directory to the PATH?)

However, I don't know what to add and where to add this.

If I open ~/.profile, it looks like this:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"

Now I want to add a directory to this

/home/newsof/mypackage/TT/V1_1

How can I add this permanently?

Moh
  • 41
  • @Zanna please read above, I know this is said before, I just could not use the previous answer understandable. I mentioned that in my text – Moh Mar 03 '17 at 22:20
  • I read your question, but I don't see your challenge. The answers to that post are very good. Add a new line to the end of your ~/.profile saying PATH=$PATH:/home/newsof/mypackage/TT/V1_1 – Zanna Mar 03 '17 at 22:23
  • @Zanna if I do that then I also should export PATH=$PATH:/home/newsof/mypackage/TT/V1_1 ? it is a temporary solution as it is said in another post like this one http://askubuntu.com/questions/109381/how-to-add-path-of-a-program-to-path-environment-variable?noredirect=1&lq=1 and this one http://askubuntu.com/questions/402353/how-to-add-home-username-bin-to-path?noredirect=1&lq=1 – Moh Mar 03 '17 at 22:28
  • no you don't need to export it (that is temporary as you say), just log out and log back in or type source ~/.profile It's permanent – Zanna Mar 03 '17 at 22:30
  • @Zanna really sorry for asking too many questions. what will happen to the other path default ? is it not better to add this one ? PATH="$HOME/bin:$HOME/.local/bin:$PATH:/home/newsof/mypackage/TT/V1_1" – Moh Mar 03 '17 at 22:32
  • @Zanna: Well, the reason why exporting isn't necessary in this case is that PATH already exists as an environment variable. It's not related to temporary vs. persistent. – Gunnar Hjalmarsson Mar 03 '17 at 22:33
  • @GunnarHjalmarsson I think I understand that, I meant that if OP did not change any config and ran export PATH=foobar then it would not persist (but in other situations we do want to set PATH temporarily and run such a command) – Zanna Mar 03 '17 at 22:38
  • @Zanna: I know you know it. But it wasn't clear from your comment. ;) – Gunnar Hjalmarsson Mar 03 '17 at 22:40
  • @nik nothing will happen to it, since it gets set again, you are adding to it. if I do FOO=bar ; FOO=$FOO:bar ; echo $FOO I will get bar:bar – Zanna Mar 03 '17 at 22:41
  • @GunnarHjalmarsson :D thank you for clarifying. It must be bedtime here... – Zanna Mar 03 '17 at 22:42
  • @Gunnar Hjalmarsson thanks for your valuable comments – Moh Mar 03 '17 at 22:45
  • You're very welcome! :D – Zanna Mar 03 '17 at 22:46

1 Answers1

0

You can use /etc/environment to set PATH environment variable, but it does not support variable expansion.

See this Link to get more information about enviroment variables

  • better to set it locally, unless there is a very good reason for using /etc/environment – Zanna Mar 03 '17 at 22:30