How to install maven on redhat linux
Go to mirror.olnevhost.net/pub/apache/maven/binaries/ and check what is the latest tar.gz file
Supposing it is e.g. apache-maven-3.2.1-bin.tar.gz, from the command line; you should be able to simply do:
wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.1-bin.tar.gz
And then proceed to install it.
UPDATE: Adding complete instructions (copied from the comment below)
- Run command above from the dir you want to extract maven to (e.g. /usr/local/apache-maven)
run the following to extract the tar:
tar xvf apache-maven-3.2.1-bin.tar.gz
Next add the env varibles such as
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.1
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
Verify
mvn -version
I made the following script:
#!/bin/bash# Target installation locationMAVEN_HOME="/your/path/here"# Link to binary tar.gz archive# See https://maven.apache.org/download.cgi?html_a_name#FilesMAVEN_BINARY_TAR_GZ_ARCHIVE="http://www.trieuvan.com/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz"# Configuration parameters used to start up the JVM running Maven, i.e. "-Xms256m -Xmx512m"# See https://maven.apache.org/configure.htmlMAVEN_OPTS="" # Optional (not needed)if [[ ! -d $MAVEN_HOME ]]; then # Create nonexistent subdirectories recursively mkdir -p $MAVEN_HOME # Curl location of tar.gz archive & extract without first directory curl -L $MAVEN_BINARY_TAR_GZ_ARCHIVE | tar -xzf - -C $MAVEN_HOME --strip 1 # Creating a symbolic/soft link to Maven in the primary directory of executable commands on the system ln -s $MAVEN_HOME/bin/mvn /usr/bin/mvn # Permanently set environmental variable (if not null) if [[ -n $MAVEN_OPTS ]]; then echo "export MAVEN_OPTS=$MAVEN_OPTS" >> ~/.bashrc fi # Using MAVEN_HOME, MVN_HOME, or M2 as your env var is irrelevant, what counts # is your $PATH environment. # See http://stackoverflow.com/questions/26609922/maven-home-mvn-home-or-m2-home echo "export PATH=$MAVEN_HOME/bin:$PATH" >> ~/.bashrcelse # Do nothing if target installation directory already exists echo "'$MAVEN_HOME' already exists, please uninstall existing maven first."fi
Pretty much what others said, but using "~/.bash_profile" and step by step (for beginners):
- Move to home folder and create a new folder for maven artifacts:
cd ~ && mkdir installed-packages
- Go to https://maven.apache.org/download.cgi and wget the latest artifact:
- If you don't have wget installed:
sudo yum install -y wget
cd ~/installed-packages
wget http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
- If you don't have wget installed:
- Uncompress the downloaded file:
tar -xvf apache-maven-3.5.0-bin.tar.gz
- Create a symbolic link of the uncompressed file:
ln -s ~/installed-packages/apache-maven-3.5.0 /usr/local/apache-maven
- Edit
~/.bash_profile
(This is where environment variables are commonly stored):vi ~/.bash_profile
- Add the variable:
MVN_HOME=/usr/local/apache-maven
(do this before PATH variable is defined)- (For those who don't know
vi
tool: Pressi
key to enable insert mode)
- (For those who don't know
- Go to the end of the line where PATH variable is defined and append the following:
:$MVN_HOME:$MVN_HOME/bin
- Save changes
- (For those who don't know
vi
tool: Pressesc
key to exit insert mode and:wq!
to save and quit file)
- (For those who don't know
- Reload environment variables:
source ~/.bash_profile
- Confirm that maven command now works properly:
mvn --help