1

I exported env variables(PYTHON,SPARK,ZEPELLIN). I looked at Setting environment variables on OS.

I want to run the Apache Zeppelin notebook.

grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
launchctl setenv JAVA_HOME /Library/java/JavaVirtualMachines/adoptopenjdk-8.jdk/contents/Home/
launchctl setenv JRE_HOME /Library/java/JavaVirtualMachines/openjdk-14.0.1.jdk/contents/Home/jre/
launchctl setenv SPARK_HOME /usr/local/Cellar/apache-spark/2.4.5/libexec
launchctl setenv SBT_HOME /usr/local/bin/sbt
launchctl setenv ZEPPELIN_HOME /usr/local/bin/zeppelin-0.9.0-preview1-bin-all
launchctl setenv PYSPARK_PYTHON /usr/local/bin/python3.8
launchctl setenv PYSPARK_DRIVER_PYTHON jupyter
launchctl setenv PYSPARK_DRIVER_PYTHON_OPTS notebook
launchctl setenv PYTHON_HOME /usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/bin

When I try to run:

bin/zeppelin-daemon.sh start

I get:

zsh: no such file or directory: bin/zeppelin-daemon.sh

The same error with

zeppelin-0.9.0-preview1-bin-all/bin/zeppelin-daemon.sh

I checked env variables

echo $[ZEPPELIN_HOME]
0

I deleted .zshrc and edited ~./zprofile

export JAVA_HOME=/Library/java/JavaVirtualMachines/adoptopenjdk-8.jdk/contents/Home/
export JRE_HOME=/Library/java/JavaVirtualMachines/openjdk-14.0.1.jdk/contents/Home/jre/
export SPARK_HOME=/usr/local/Cellar/apache-spark/2.4.5/libexec
export SBT_HOME=/usr/local/bin/sbt
export ZEPPELIN_HOME=/usr/local/bin/zeppelin-0.8.1-bin-all
export PYSPARK_PYTHON=/usr/local/bin/python3.8
export PYSPARK_DRIVER_PYTHON=jupyter
export PYSPARK_DRIVER_PYTHON_OPTS='notebook'

export PATH=$JAVA_HOME/bin:$SPARK_HOME:$SPARK_HOME/bin:$SPARK_HOME/sbin:$SBT_HOME/bin:$ZEPPELIN_HOME/bin:$PATH
export PATH=$PYTHON_HOME/usr/local/Cellar/python@3.8/3.8.3/Frameworks/Python.framework/Versions/3.8/bin:$PATH

Now echo $[JAVA_HOME] shows

zsh: bad math expression: operand expected at `/Library/j...'

Why? How to fix this?

MikiBelavista
  • 2,470
  • 10
  • 48
  • 70
  • If, when starting a program, you provide an explicit path component, as your `bin` when doing `bin/zeppelin-daemon.sh`, PATH is not searched and the file must exist in that very location below your working directory. The error message you got here, has nothing to do with the environment. Of course once the script has been started, the environment must be correct, but you obviously did not get so far yet. – user1934428 Jul 09 '20 at 07:07
  • Aside from this, a good place to store the environment variables for zsh is `~/.zshenv`, because this is the only file in your home directory, which is guaranteed to be processed by each invocation of zsh. See the section titled _INVOCATION_ in `man zsh`. – user1934428 Jul 09 '20 at 07:11

1 Answers1

2

I googled and find out that for Catalina OS env variables should be placed into

.zshrc

Now everything works fine.

MikiBelavista
  • 2,470
  • 10
  • 48
  • 70
  • 1
    Put environment variables in `.zprofile`. `.zshrc` is sourced by every interactive shell, which can usually inherit environment variables from an initial login shell (which is what will source `.zprofile`). – chepner Jul 08 '20 at 12:32
  • @chepner Thanks,but what kind of difference does it make? – MikiBelavista Jul 08 '20 at 13:22
  • 1
    If you start a new interactive shell, it avoids unnecessarily resetting (or worse, redundantly appending to) the existing value. – chepner Jul 08 '20 at 13:24
  • @MikiBelavista : Your solution works only for interactive zsh. A non-interactive zsh would not process this file. – user1934428 Jul 09 '20 at 07:14
  • @chepner : The problem with `.zprofile` is that it is only processed by login shells. If for instance a user's login shell is set to something different than zsh, and this user later opens an interactive zsh via a terminal (this is for instance the setup I am using on my Mac), the file would not be processed. Redundantly appending an existing value in a new interactive shell is trivial to avoid, so this would not really be a problem. – user1934428 Jul 09 '20 at 07:17
  • @user1934428 Nice explanation, but what do you suggest? – MikiBelavista Jul 09 '20 at 07:27
  • I wrote this in my 2nd comment to your question. And of course I would make sure, that environment variables, which are appended to existing ones, get not appended repeatedly if new zsh child processes are created. If you look at what files are processed on zsh startup, you know well what happens exactly in each zsh process, and you can put your settings to those places where they fit you best. It's yours to decide. – user1934428 Jul 09 '20 at 07:32
  • @user1934428 If you exporting variables, they will be inherited from the login shell. Make sure they are set in the login shell's configuration file. – chepner Jul 09 '20 at 12:48
  • Of course. But if the login shell is never executed? The login shell can be set via chsh to anything (in my case, it's bash), and if I don't explicitly invoke zsh via the login option, the settings don't apply. Of course I don't know the setup in the machine of the OP. That's why I recommended to get familiar which what files are sourced in any case he is interested in. – user1934428 Jul 09 '20 at 13:48
  • @chepner : Another case I experienced that my zsh was not run as login shell, was in the context of Jenkins jobs. cron jobs too might (perhaps?) not have a parent zsh which was a login shell - not sure about this, though. – user1934428 Jul 09 '20 at 13:56
  • 1
    Jenkins isn't running from *your* environent, and I would be surprised if it starts an interactive shell that would source `.zshrc`. – chepner Jul 09 '20 at 14:01
  • @chepner : You are right. Actually, I remember that had to set ZDOTDIR before executing the shell, otherwise it wouldn't have located by `.zshenv` either. And, thinking of it, since I can always specify explicitly, whether my shell is a login shell (by providing the `-l` option on invocation), I agree that I can of course define my environment settings in `.zprofile` too. – user1934428 Jul 10 '20 at 10:04
  • 1
    zsh is a shell, like bash, every shell has it's own configuration file. Probably you're looking for a solution valid system-wide, which is not the case of .zshrc: variables set in this file will be loaded only when a zsh shell is started. If an external command will be executed in bash, the variable will not be found! Check this article: https://medium.com/@youngstone89/setting-up-environment-variables-in-mac-os-28e5941c771c – funder7 Dec 14 '20 at 21:03