0

I was trying to set up the mvn command, I downloaded maven on the official Apache website and wrote export M2_HOME="/Users/Bohan/apache-maven-3.9.0" PATH="${M2_HOME}/bin:${PATH}" export PATH in the bash_profile. Then I tried command mvn -version to see if it works, it doesn't and shows Command not found 'mvn'. I searched and it says i need to type source .bash_profile to update the commands, then it works. Then I found out I have to type source .bash_profile every time I use a maven command.

I was expecting that once I configure the bash_profile and update the commands, it will work afterwards. It doesn't in fact I need to update the commands every time I use it. I tried restarting my computer. Closing terminal and reopening it which both didn't work. Same thing resulted, I need to update the commands every time. All answers were appreciated.

Edit: I was using MacOS, and i am not using Ubuntu(I will look into Ubuntu and SDKMAN.)

Edit 2: Thanks to Dan_Maff for pointing out I should change my bash_profile to bash. It was fixed but I'm curious why does it work?

Edit 3: Now I'm using it in IntelliJ Idea and it seems like the same problem...

acrastt
  • 104
  • 1
  • 7
  • (1) In Ubuntu, the configuration file I usually modify is `~/.bashrc` (2) What operating system do you use? (3) Have you considered using SDKMAN? After installing SDKMAN, you can install JDK, Maven, Gradle through SDKMAN. – life888888 Feb 26 '23 at 04:02
  • 4
    Did you change your macOS default shell to `bash`? It normally uses zsh as far as I know. If you didn't change to bash, you should configure zsh instead. – Dan_Maff Feb 26 '23 at 04:17

1 Answers1

0

according to this, you can add a permanent path to $PATH using this command (on MacOS):

sudo -s 'echo "/Users/Bohan/apache-maven-3.9.0" > /etc/paths.d/mvn'

and according this, you can set any environment variable globally using this command:

sudo launchctl setenv M2_HOME "/Users/Bohan/apache-maven-3.9.0"
Mostafa Nazari
  • 616
  • 7
  • 21