Mac High Sierra JAVA_HOME - java-home

I'm running High Sierra, have Java9 installed, but need to default to jdk1.8.
I added the following line to ~/.bash_profile and ~/.bashrc, both individually and at the same time.
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home"
When I open a new terminal "java -version" would show java9, and "echo $JAVA_HOME" prints nothing.
Finally I just deleted Java9, but can you still specify a default java version or does it just default to the latest version no matter what?

Related

Set environment variable path for maven (mvn) in mac for Catolina or higher version

When I am trying to set environment variables for mvn in MAC, I am able to set for one session but if I open another terminal and try mvn -version, it doesn't work.
Commands I followed:
vi $HOME/.z_profile
--Added this path in .z_profile file
export M2_HOME=/Users/namangupta/Downloads/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin/
source .z_profile
mvn -version
--Output:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/namangupta/Downloads/apache-maven-3.6.3
Java version: 15, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-15.jdk/Contents/Home
Default locale: en_IN, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
After these steps when I open another terminal and try mvn -version I get
zsh: mvn cmd not found and on running printenv the path gets reset. Can anyone please tell me where I am wrong in setting the path?
For MacOS Catolina or higher version, since you have zsh instead of bash, you will need to change the path to another file instead of .bash_profile (used for previous versions) as shown below:
--to open the file
nano ~/.zshenv
--paste the following lines and append path for anything else if you want to, just ensure you enter the proper version u have
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home"
export M2_HOME="/Users/namangupta/Workspace/setup_files/mvn/apache-maven-3.8.1"
export PATH=$PATH:$M2_HOME/bin:$JAVA_HOME/bin
--save the file
Ctrl+x, then 'Y' to save and then Enter
--to save the environment variables path
source .zshenv
And you are good to go. To check you can try printenv to check or mvn -version or java -version or echo $PATH
For MacOS Monterey (version 12.5)
-> open ~/.zshenv
->Add following to .zshenv File
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home"
export M2_HOME="/Users/namangupta/Workspace/setup_files/mvn/apache-maven-3.8.1"
export PATH=$PATH:$M2_HOME/bin:$JAVA_HOME/bin
->Save file
->mvn -version
This solution worked for me.Thank you :)
You had everything right except the filename - it should be $HOME/.zprofile (with no underscore). That's why it worked when you manually sourced from .z_profile, but didn't work when starting a new terminal.

How to install Maven in Mac Catalina?

I just installed Maven via Mac Catalina via command line and mvn -version was showing output. then it went away. Please help.
May be a long post, but in the end you will have a convenient tool to install packages and understanding of how to configure them.
Why maven "disappeared" I have no idea of, so what I would do in this situation:
First of all, I would delete maven manually (find the directory and remove it along with any other files that were setup during maven installation)
Then I would highly recommend using Homebrew - a package manager for macOS
To install Homebrew, open terminal and execute the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Wait for a couple of minutes (a less) until it is installed
Now, that Homebrew is installed, you have a very convenient tool to install stuff on your mac
So, you want to install Maven. You can find Maven on Homebrew
Now you just have to open your terminal again and execute
brew install maven
After a few seconds brew will display the directory it installed Maven in (by default, all Homebrew packages are installed in /usr/local/Cellar/)
You are almost there, now you need to set the environment variable.
As described by Apache, the environment variable needs to be added to the PATH environment variable.
Here I have some uncertainty in terms of what file to use: .bash_profile or zprofile. The confusion is caused by the fact that in latest macOS update (maybe several latest updates) Apple decided to use zsh shell, and so .bash_profile became somewhat functionally equivalent to zprofile. There are many articles on the Internet about what file to use, so you better check them out before proceeding (sorry for not providing links).
On my Catalina 10.15.6 I use .zprofile and everything looks to work perfectly.
Once you decide what file to use, execute the following in the terminal:
nano .zprofile
An editor will open, write this:
export PATH=/usr/local/Cellar/maven/*version*/bin:$PATH
Press Control + X to exit, then Y to save changes and hit Enter to exit the editor
After that you will again be in terminal, where execute:
source .zprofile
To load it. Then close the terminal, open again and check that PATH variable is edited by executing:
env
That's it! Good luck coding!
For MacOs Catalina, below is what worked for me.
Terminal > Vim .zprofile
Add:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/Users/username/apache-maven-3.8.1 (This is where my maven folder is.)
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
Terminal > source ~/.bash_profile
Restart Terminal > mvn -version
Output:
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/username/apache-maven-3.8.1
Java version: 1.8.0_281, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
username#C02F ~ % java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
Did you try executing:
source ~/.zshrc

mvn command not found with environment variables set

Currently I am experiencing a problem with maven on my Mac OSx 10.10.5 Yosemite.
I installed the apache files today, and tried to set maven up only for it to not recognize itself.
I currently have a ~.bash_profile file with the three lines:
export JAVA_HOME=$(/usr/libexec/java_home)
export M2_HOME=/Users/vincenttomie/apache-maven-3.6.1/
export PATH=$PATH:$JAVA_HOME/bin:/Users/vincenttomie/apache-maven-
3.6.1/bin
When I do $Java_Home I get
/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home
When I do $M2_HOME I get
/Users/vincenttomie/apache-maven-3.6.1/
When I do echo $PATH I get below
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/vincenttomie/apache-maven-3.6.1/bin:/Users/vincenttomie/apache-maven-3.6.1/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin:/Users/vincenttomie/apache-maven-3.6.1/bin
When I try to do mvn -- version in the terminal it gives me the
~bash: mvn: command not found.
I was wondering if anyone knew what the problem could be.
Thank you!

updating osx terminal after macport installation

I installed macports on my macbook pro and after the successful install, I tried typing in 'port' in a terminal tab that I had was already opened before the macport installation and it gave me the error "command not found"
When I opened another tab in the terminal and tried again, it worked. (It works in the new tab but does not work in the old one)
I am guessing that this has to do with the fact that the first tab was opened before the the macport installation took place.
Just wanted to know how to refresh the terminal after I install something like macports.
PS: I know that I can open a new tab and continue working but am just curious how to do so.
General: You can use the reset command:
reset
For more information run:
man reset
MacPorts: The PATH variable is set by the postflight script to append the MacPorts executable paths to the default path:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
The location of this line depends on your shell, the installer may use .profile, .bash_login, .bash_profile, .tcshrc, or .cshrc.
If you want these changes to take effect in the current Terminal window, you either need to execute this command manually:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Or if you know which file contains the line above, you can source it. For example:
source ~/.profile

How to put psql on the path when using Postgres.app on OS X?

I've installed Postgres93 on my Mac. I can open the application, and "Open psql" through the app which opens up a command line interface with psql.
However, when I type $ which psql nothing is returned. The installation path is /Applications/Postgres93.app. How do I make $ which psql show the correct result?
Mac OS X - Mavericks
PostgreSQL package, I'm not as sure about. I went here and downloaded it - http://postgresapp.com/
I just had postgres installed and was not able to run the psql command until I ran the following command in my terminal:
export PATH="/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH"
Now the terminal knows where to find postgres when I use the psql command.
Remember to replace the version number '9.5' with your current version.
I had the same problem with nothing showing for the which psql command till I run the command below to resolve it. The command provided below is just a little tweak of what has already been provided by others here. The only difference is, instead of providing a specific postgres version number in the command, you can simply tell postgres to use the latest postgres version by simply running the following command:
export
PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
And now my terminal was able to find the path to postgres when I run which psql.
Hope this helps.
On macOS Mojave these instructions work well:
If your Postgres has not been installed yet, I suggest you use the great "brew" package manager from here https://brew.sh/ :
$ brew cask install postgres
or you can install it usual way from the website
Put this to the bottom of your ~/.bash_profile file:
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:${PATH}"
Restart your terminal or restart your ~/.bash_profile directly with the command:
$ . ~/.bash_profile
Verify your installation:
$ psql --version
** Edited: to include a permanent fix, not just during your current session. **
I had this same problem, and also found a clear answer lacking in the docs.
To fix:
Download the new app, and follow the instructions to move it to the Applications folder
Add the new bundle to your path by typing the following in your Terminal (version number specific - mine is 9.4):
PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"
To fix the issue on a permanent basis, run the same line but with export in front:
export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"
It appears that you installed Heroku's Postgres.app, which is a tool intended for throw-away testing and development. Add the contents of the bundle to your PATH by following the instructions in the Postgres.app documentation - see "command line tools".
On macos mojave i've added the following line on my ~/.profile :
export PATH=$PATH:/Library/PostgreSQL/10/bin
the psql command line client lies into this folder. i've used the enterprisedb installer.
I just experienced the same problem, and solved it by adding export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin to .bash_profile. Note that this line is version-specific, so be sure to check this line against your current version of Postgres.app.
Using Mac OS Monterey, the latest Homebrew (3.4.0) and postgres#13.
I was able to add psql to the path by using -
export PATH="/opt/homebrew/Cellar/postgresql#13/13.6/bin:$PATH"
Replace #13 and 13.6 with your version.
The latest homebrew install location seems to be /opt/homebrew/*
I'm using catalina 10.15.3 and I had the same issue after installing psql using homebrew. Then I noticed, homebrew mentioned
==> libpq
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.
If you need to have libpq first in your PATH run:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile
So, I ran 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile and psql was added to my path
In Mac, there is a SQL Shell application already under /Applications/PostgresSQL
try that
Also, you can run /Library/PostgreSQL/11/scripts/runpsql.sh
In my case, I installed Postgres12 and had the same issue. I had to look out for the location of my bin folder. It happened to be in /Applications/2ndQuadrant/PostgreSQL/12/bin. So I had to run export PATH="/Applications/2ndQuadrant/PostgreSQL/12/bin:$PATH" in my terminal and restart the terminal. That solved it.

Resources