-2

I have downloaded Scala to ~/bin for easy access on my machine; but I seem to have some difficulty adding it to the PATH.

On my MacBook I simply added the following to ~/.profile and everything just worked:

SCALA_HOME=$HOME/bin/scala-2.11.7
PATH=$PATH:$SCALA_HOME/bin

On my Linux box however, I've tried putting the same code in both ~/.profile and ~/.zshrc, and it still doesn't correctly display /home/coffee/bin/scala-2.11.7/bin/scala when running which scala.

source .zshrc doesn't work at all, and source .profile only works until I re-open the console (I put the code into both just in case).

So what am I doing wrong here, and how do I get it to work?

7
  • Sounds like you are using Elementary OS. Elementary OS is off topic here on Ask Ubuntu.
    – Thomas Ward
    Jan 24, 2016 at 23:22
  • @ThomasW. does that even really matter? it's ubuntu-based and got the same exact internals; add to that zsh runs on both Jan 24, 2016 at 23:24
  • If it displayed /Users/coffee/bin/scala-2.11.7/bin/scala I'd be amazed. This isn't OSX, whatever Linux distro you maybe using. And questions on elementary OS belong on Unix & Linux or elementary OS.
    – muru
    Jan 24, 2016 at 23:32
  • @muru and why would you be amazed? all it should do is echo the path; which it correctly does when sourcing the profile Jan 24, 2016 at 23:34
  • 1
    Because neither elementary OS nor Ubuntu typically has home directories in /Users, they typically use /home/. If you're using a common home directory on OSX and Linux, well, who knows what else is going wrong with your shell configuration.
    – muru
    Jan 24, 2016 at 23:35

1 Answer 1

2

The fact that PATH is not sourced from ~/.profile has 2 very good reasons behind it:

  1. Only login shells source ~/.profile. So that's not expected to be sourced in a normal terminal. If you're unable to get it to work in a login shell that's because
  2. Zsh sources ~/.zprofile, not ~/.profile.

The fact that the changes are lost after sourcing ~/.profile is expected, since what is sourced affects only the current shell; that's why ~/.profile / ~/.zprofile are sourced each time the shell starts.

The fact that it works when sourcing ~/.profile and not when sourcing ~/.zshrc is apparently unexplainable.

My guess is that an export / source is messing with PATH later / you're just running the wrong commands in ~/.zshrc.

3
  • I wonder, could it be because it exports path by default somewhere within the file? causing it to overwrite the changes Jan 24, 2016 at 23:58
  • @ElectricCoffee That may well be, I assumed you were sure that's wasn't happening. grep '^\(source\|export\)' ~/.bashrc to quickly see the chain of sources / exports.
    – kos
    Jan 25, 2016 at 0:01
  • I did a cat .zshrc | grep PATH and lo and behold, it did already define an export. That was the bug after all. But thanks for the explanation anyway Jan 25, 2016 at 0:03

You must log in to answer this question.

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