I installed openJDK8 on a Raspberry Pi 0H with RaspiOS Lite (BUSTER). I also installed wiringpi and pi4j libraries. I added the directories to CLASSPATH in the /etc/environment file and even tried to export it, but java & javac seem to ignore the variable. I have to specify the classpath every time I compile or run my code. GOOGLE does not show any info on it, every mention I found was to use -cp.

Is there no way to specify a CLASSPATH variable for openJDK8?

  • Why not export it from /home/pi/.bashrc?
    – Dougie
    Jul 7, 2020 at 7:53
  • 1
    Two things; add the contents of /etc/environment to your post, and double check the value is what you think it is by including the output of echo $CLASSPATH
    – Nick
    Jul 7, 2020 at 16:48
  • There's not enough information here to rule out errors by the OP, hence "non-reproducible" at this point.
    – goldilocks
    Dec 10, 2021 at 15:25

2 Answers 2


/etc/environment is not yet another startup script, it's a configuration file. As a result, "exporting" variables in it is simply a syntax error (see the man page for the correct syntax), and the applicability of any settings there to your session depends on PAM/systemd configuration. If your java process is not ultimately started by a systemd --user instance or a process which uses PAM, it will never see those variables you set in /etc/environment.

Unless there is a good reason to set CLASSPATH in a different place, I would set it directly in the command you use to run Java (java -cp path1;path2)

  • This is a little bit contra man 5 environment and this answer on U&L; by that, /etc/environment is used by PAM -- ie. login, which is used in the background by display managers (that present GUI logins) [or not see further comments], meaning those variables should be set for every user which logs in, and has no direct relationship to systemd, whose conf files are in /etc/systemd/.
    – goldilocks
    Dec 10, 2021 at 15:23
  • @goldilocks Interesting. When I run man 5 environment on the Pi, I get "Configuration files in the environment.d/ directories contain lists of environment variable assignments for services started by the systemd user instance. systemd-environment-d-generator(8) parses them and updates the environment exported by the systemd user instance." Furthermore, my GUI session is started by lightdm.service, I think login is only involved in console sessions, which are in turn started by [email protected] instances. Dec 10, 2021 at 16:46
  • Huh -- are you sure that isn't man 5 environment.d (<- note the .d suffix)? What comes up for man 5 environment on RpiOS buster (I haven't upgraded to bullseye, but it is the same on fedora 34 x86-64, which has to be as up-to-date as it gets systemd wise) is (I just noticed this) the same page as for man pam_env.conf. The environment.d page just notes that there is a symlink to /etc/environment for backward compatibility. lighdm is a display manager (dm), but my statement about them from the first comment is...
    – goldilocks
    Dec 10, 2021 at 19:42
  • ...I think incorrect (now, at least); they don't apply login, although it looks like they still use PAM (but I did not check lightdm specifically). In any case, pretty sure I'm still right that what this means is /etc/environment should apply no matter how the user session was instantiated, since either PAM or the systemd mechanism is used.
    – goldilocks
    Dec 10, 2021 at 19:42
  • 1
    @goldilocks Thanks for the clarification! My point was mostly that it's a configuration file rather than a shell script, so shell script format will not work in this file. Dec 10, 2021 at 21:43

As a general rule it's a bad idea to set the classpath at the user or OS level.

You better set it up during build using Ant, Maven, or Gradle. At runtime you can set it on the startup BASH/SH script.

Why? Because different applications may want to use different libraries. Maybe even different versions of the same library. If you set it at the user level, then one app may end up running the correct version of the library, but another will run (and inexplicable crash) since it's running the wrong one for itself.

Not the answer you're looking for? Browse other questions tagged or ask your own question.