title: How exactly to set up and use environment variables on a Mac?
body: <p>What is the proper (2021 way) of creating a permanent environment variable on a Mac (macOS Big Sur) and then use it within a Java project.</p>
  <p>There are many very old posts regarding this topic. None of them seem to work properly nowadays.</p>
  <ol>
  <li>How to add a permanent environment value (through terminal)?</li>
  <li>And how can I use it in a Java code?</li>
  </ol>
  <p>I'm also not sure how I was able to add my <code>testvar=testvalue</code> to the list, because I tried so many files (although it seems none of them worked), by adding <code>export testvar=testvalue</code> to the following files:</p>
  <ul>
  <li>/etc/paths</li>
  <li>~/.bashrc</li>
  <li>~/.bash_profile</li>
  <li>~/.profile</li>
  <li>/etc/profile</li>
  </ul>
  <p>Also after inserting it into each file I used <code>source {file}</code>.</p>
  <p>So at this point I have no idea which is the proper way to create and have it permanently, and being able to use it in my Java code.</p>
  <p>So far, I can print the variables into the terminal like this:</p>
  <pre><code>printenv
  </code></pre>
  <p>My variables are getting listed, example:</p>
  <pre><code>testvar=testvalue
  </code></pre>
  <p>In my Java code, I get <strong>null</strong> when using:</p>
  <pre><code>System.getenv(&quot;testvar&quot;)
  </code></pre>
  <p>However using an other variable names that were not created by me, but the macOS system (eg. &quot;USER&quot;) prints the value as expected.</p>