i'm trying to install maven on my mac first i downloaded apache-maven-3.3.9 and then i entered this code on my bash:
export M2_HOME=$(/usr/local/apache-maven/apache-maven-3.3.9)
and
export PATH=${PATH}:/Users/sabrine/ant/bin:$JAVA_HOME/bin:$ANT_HOME/bin:$M2_HOME/bin:
but it doesn't work i got(i tried with mvn -v)
-bash: mvn: command not found
where is the problem? what should i do?
Please follow below steps on terminal
Create bash profile (will be created under home folder and will be hidden file)
$ touch .bash_profile
Edit bash profile in editor and put next 2 commands in file, save file.
export M2_HOME=/Users/srajp/apache-maven-3.5.3
export PATH=$PATH:/Users/srajp/apache-maven-3.5.3/bin
Then check Maven version
$ mvn --version
If needed please see detailed steps on my blog on How to install Maven on MAC OS?
Don't add $( ) around the paths, just use:
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
Followed by yours:
export PATH=${PATH}:/Users/sabrine/ant/bin:$JAVA_HOME/bin:$ANT_HOME/bin:$M2_HOME/bin:
The above assumes that your maven installation is in /usr/local/apache-maven/apache-maven-3.3.9, and ls -ld /usr/local/apache-maven/apache-maven-3.3.9 gives non-error output.
You can install maven on mac using this command.
brew install maven
Related
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!
I have set correct path of JAVA and maven in mac still i am getting error when i try to see maven version: -bash: mvn: command not found
I have set path in bash file as below:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
export MAVEN_HOME=/Users/aadityaverma/Downloads/apache-maven-3.6.0
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
Note:
java -version - it is working fine, but
mvn --version Getting error as mentioned above,
mvn -version Getting error as mentioned above
Modify .bash_profile as follow:
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
Then restart CLI and run maven again
mvn -version
More information about Important Java directories on Mac OS
I have installed SDK doing brew cask install android-ndk and NDK doing brew cask install android-ndk, everything was ok during the installation and inserted the PATH, like this:
export GRADLE_HOME=/usr/local/opt/gradle
export ANDROID_HOME=/usr/local/Caskroom/android-sdk/3859397
export ANDROID_NDK_HOME=/usr/local/Caskroom/android-ndk/16b/android-ndk-r16b
export ANDROID_SDK_ROOT=/usr/local/Caskroom/android-sdk/3859397
export PATH=$GRADLE_HOME/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
Saved and committed doing source ~/.bash_profile.
After, I tried to run my gradle task, during start of compile of a C++ library, I got this:
* What went wrong:
A problem occurred configuring project ':some-library'.
> NDK not configured.
Download it with SDK manager.
Is there any way to solve it?
Thank you.
In macOS installed with brew use this the following paths
In file ~/.bash_profile
export ANDROID_NDK_HOME = /usr/local/share/android-ndk
export ANDROID_HOME = /usr/local/share/android-sdk
If you are using another bash script or zsh for example, you should put it begin of that script file, eg.
myortherscript.sh
#!/bin/bash
# THIS AT TOP
source ~/.bash_profile
Important: This sample I'm considering the same user for configuration bash_profile and script execution.
I have maven3.1.1 and maven3.2.5 installed on my mac.
When I do mvn -version it shows maven3.1.1
How can I switch to the other maven version 3.2.5 ?
Your Current bash profile would be pointing to the maven version 3.1.1 as shown below
~/.bash_profile
export M2_HOME=/Users/yourusername/apache-maven-3.1.1 (Path where you have installed maven 3.1.1)
export PATH=$PATH:$M2_HOME/bin
Change the bash profile as shown below
~/.bash_profile
export M2_HOME=/Users/yourusername/apache-maven-3.2.5 (Maven 3.2.5 path)
export PATH=$PATH:$M2_HOME/bin
Restart the terminal and hit command mvn -version and now it will be pointing to the latest version.
Using SDKMan might be a simpler way to switch between multiple Maven versions.
1) Install SDKMan which is a one-off thing: http://sdkman.io/install.html
2) Do sdk install maven yourVersion
3) To switch: sdk install maven anotherVersion
4) To switch again: sdk use maven yourVersion
SDKMan should simplify such operations for several other software frameworks like Java, Groovy, Spring, Gradle, etc.
Another way to create a soft link. Suppose you have two version like -
maven-v1 and
maven-v2
Now if you want to use maven-v1 then create a soft link -
ln -s /installation/directory/of/maven-v1 maven
Then in your .bash_profile export M2_HOME pointing this directory -
export M2_HOME=/path/to/maven
export PATH=$PATH:$M2_HOME/bin
If you are doing this at first time then you need to restart your terminal.But after that you just need to change the soft link to you expected version. Suppose, now you want to use maven-v2; just change the existing soft link -
ln -sf /installation/directory/of/maven-v2 maven
Now you don't need to restart the terminal.
In your ~/.bash_profile
Download the tar of the maven version you want to use and extract the contents you want to use. Example Maven 3.1.1
export M2_HOME=/Users/<path to maven>/apache-maven-3.1.1
export PATH=$PATH:$M2_HOME/bin
If you have zsh, then change the ~/.zprfile
do not use M2_HOME. directly go for export PATH=$PATH:/usr/{maven...path}/bin
I've developed a function for ~/.zshrc and ~/.bashrc files to choose a different maven version according to the project without having to install more maven versions but taking advantage of docker.
So I use my maven installed in my machine with: mvn clean install
And I use my maven in docker with: maven jdk8 clean install or maven jdk11 package for example.
Here the function:
# executes a containerized version of maven so you won't have to install to your computer.
# you need to have docker installed and running.
# you can specify 'jdk8' or 'jdk11' as first argument to switch jdk.
# if not specified, jdk11 is the default.
# usage example:
# /your/maven/project/directory - $ maven jdk8 clean install
# /your/maven/project/directory - $ maven clean package
maven() {
if [[ "$1" == "jdk8" ]]; then
docker run --rm -v $PWD:/usr/src/app -v $HOME/.m2:/root/.m2 -w /usr/src/app maven:3.8-adoptopenjdk-8 mvn "${#:2}"
elif [[ "$1" == "jdk11" ]]; then
docker run --rm -v $PWD:/usr/src/app -v $HOME/.m2:/root/.m2 -w /usr/src/app maven:3.8-eclipse-temurin-11 mvn "${#:2}"
else
docker run --rm -v $PWD:/usr/src/app -v $HOME/.m2:/root/.m2 -w /usr/src/app maven:3.8-eclipse-temurin-11 mvn "$#"
fi
}
Please help me, I try to set tup maven 3.3.3 on macbook pro yosemite but wrong. I did it bellow:
Download apache-maven-3.3.3
Extract it to /usr/local
Open terminal and do these follow step:
cd /usr/local
export PATH=$PATH:/usr/local/apache-maven/apache-maven-3.3.3/bin
export JAVA_HOME=/usr/java/jdk1.8.0_25
restart terminal
mvn -version
But it show error:
-bash: mvn: command not found.
I am a beginner developer. Please help me.Thanks all
To manage java version you can use jenv
Edit .bash_profile
export M2_HOME=~/Documents/Tools/apache-maven-3.3.1
export PATH=$M2_HOME/bin:$PATH