Before marking this as duplicate, I went through these posts, but nothing helped.
'mvn' is not recognized as an internal or external command,
Getting -bash: mvn: command not found,
Can't access mvn command from command line?
Some are specific to windows and did not help. A couple of them on Mac OS X gave suggestions, that I tried but did not help.
What I tried (this is exactly what Maven suggests):
Extract the distribution archive, i.e. apache-maven-3.1.1-bin.tar.gz
to the directory you wish to install Maven 3.1.1. These instructions
assume you chose /usr/local/apache-maven. The subdirectory
apache-maven-3.1.1 will be created from the archive. In a command
terminal, add the M2_HOME environment variable, e.g. export
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1. Add the M2
environment variable, e.g. export M2=$M2_HOME/bin. Optional: Add the
MAVEN_OPTS environment variable to specify JVM properties, e.g. export
MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used
to supply extra options to Maven. Add M2 environment variable to your
path, e.g. export PATH=$M2:$PATH. Make sure that JAVA_HOME is set to
the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02
and that $JAVA_HOME/bin is in your PATH environment variable. Run mvn
--version to verify that it is correctly installed.
I see that on the terminal that I used for installation, it works fine. I do not have this issue. but when I tried on a new terminal, I get command not found.
I also added export PATH=$M2 to my .bashrc, I did source and then restarted the terminal, still it did not help.
can someone suggest how to make it available in all sessions of terminal?
Thanks
Try following these if these might help:
Since your installation works on the terminal you installed, all the exports you did, work on the current bash and its child process. but is not spawned to new terminals.
env variables are lost if the session is closed; using .bash_profile, you can make it available in all sessions, since when a bash session starts, it 'runs' its .bashrc and .bash_profile
Now follow these steps and see if it helps:
type env | grep M2_HOME on the terminal that is working. This should give something like
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
typing env | grep JAVA_HOME should give like this:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Now you have the PATH for M2_HOME and JAVA_HOME.
If you just do ls /usr/local/apache-maven/apache-maven-3.1.1/bin, you will see mvn binary there.
All you have to do now is to point to this location everytime using PATH. since bash searches in all the directory path mentioned in PATH, it will find mvn.
now open .bash_profile, if you dont have one just create one
vi ~/.bash_profile
Add the following:
#set JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
save the file and type source ~/.bash_profile. This steps executes the commands in the .bash_profile file and you are good to go now.
open a new terminal and type mvn that should work.
Solutions above are good but they require ~/.bash_profile. /usr/local/bin is already in the $PATH and it can be confirmed by doing echo $PATH. Download maven and run the following commands -
$ cd ~/Downloads
$ tar xvf apache-maven-3.5.3-bin.tar.gz
$ mv apache-maven-3.5.3 /usr/local/
$ cd /usr/local/bin
$ sudo ln -s ../apache-maven-3.5.3/bin/mvn mvn
$ mvn -version
$ which mvn
Note: The version of apache maven would be the one you will download.
Here is what worked for me.
First of all I checked if M2_HOME variable is set env | grep M2_HOME. I've got nothing.
I knew I had Maven installed in the folder "/usr/local/apache-maven-3.2.2", so executing the following 3 steps solved the problem for me:
Set M2_HOME env variable
M2_HOME=/usr/local/apache-maven-3.2.2
Set M2 env variable
M2=$M2_HOME/bin
Update the PATH
export PATH=$M2:$PATH
As mentioned above you can save that sequence in the .bash_profile file if you want it to be executed automatically.
I got same problem, I tried all above, nothing solved my problem. Luckily, I solved the problem this way:
echo $SHELL
Output
/bin/zsh
OR
/bin/bash
If it showing "bash" in output. You have to add env properties in .bashrc file (.bash_profile i did not tried, you can try) or else
It is showing 'zsh' in output. You have to add env properties in .zshrc file, if not exist already you create one no issue.
The possible solution can be that maven is not installed in your mac system.
Use this command to install maven:
brew install maven
And, to verify, that it is successfully installed, run this command:
mvn -v
If it returns you maven version, then maven is successfully installed in your system.
steps to install maven :
download the maven file from http://maven.apache.org/download.cgi
$tar xvf apache-maven-3.5.4-bin.tar.gz
copy the apache folder to desired place $cp -R apache-maven-3.5.4 /Users/locals
go to apache directory $cd /Users/locals/apache-maven-3.5.4/
create .bash_profile $vim ~/.bash_profile
write these two command :
export M2_HOME=/Users/manisha/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin
7 save and quit the vim :wq!
restart the terminal and type mvn -version
I followed brain storm's instructions and still wasn't getting different results - any new terminal windows would not recognize the mvn command. I don't know why, but breaking out the declarations in smaller chunks .bash_profile worked. As far as I can tell, I'm essentially doing the same thing he did. Here's what looks different in my .bash_profile:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH JAVA_HOME
J2=$JAVA_HOME/bin
export PATH J2
M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export PATH M2_HOME
M2=$M2_HOME/bin
export PATH M2
You probably have 2 types of shell instances.
sh vs zsh.
Both can have different path defined.
Check your PATH environment variable by typing the below line in terminal
echo $PATH
To test you can change shell mode -
sh to zsh -> type zsh and press enter in terminal (notice $ changes to %)
zsh to sh -> type sh/bash and press enter in terminal (notice % changes to $)
In Both shell modes check for PATH env.
Make both same, or append path from other as needed.
Commands running in 1 shell and not in other would be sorted.
For some of you the cause might be using of other variables in the path to the maven directory. More details in the answer.
Related
I am new to bash/shell scripting and need to undo the effects created when I ran the command
export PATH=~/.local/bin:$PATH
and
export PATH=~/C:\Users\I860605\AppData\Roaming\Python\Python39\Scripts:$PATH
I was attempting to troubleshoot a Reuse tool and entered the command thinking it would fix the issue, however as a result none of my commands in Git Bash seem to work any longer, and normal commands for Python and other dependencies now result in command not found errors.
I also noticed that now my Git Bash CLI no longer picks up whether I'm cd'd into any of my repositories, with no display of (main) branch etc.
I found some other articles that were somewhat related to this, but they were for Ubuntu and Mac users, not for Git Bash on Windows, which is my scenario.
When I ran the command echo $Path, this is what was returned:
echo $Path
/c/Users/I860605/C:UsersI860605AppDataRoamingPythonPython39Scripts:/c/Users/I860605/.local/bin:/c/Users/I860605/.local/bin:C:UsersI860605AppDataRoamingPythonPython39Scripts
I saw that I could perhaps run source ~/.bash_profile or source ~/.bashrc and edit the file contents from there, but both commands return No such file or directory
How would I go about setting my Path back to how it was before this blunder?
If you don't want to open a new session, the simplest approach is:
to have a ~/.bashrc (with ~ or $HOME set by default to %USERPROFILE%)
set your PATH in it (like your export PATH=$PATH:~/.local/bin)
type "source ~/.bashrc": that will reset the PATH of the current session.
Type echo $PATH to then check the path is indeed at the expected value.
I installed Maven on macOS 10.12.6.
Added environment to .bash_profile file:
export PS1="\h --- \t *************************** \w $ "
export JAVA_HOME=$(/usr/libexec/java_home)
export MAVEN_HOME=/Users/{user}/Documents/Path/Maven/maven_3.3.9
export GRADLE_HOME=/Users/{user}/Documents/Path/Gradle/gradle_6.1.1
export PATH=$PATH:$MAVEN_HOME/bin
export PATH=$GRADLE_HOME/bin:$PATH
After that I save it and set source .bash_profile command in Terminal.
When I try in Terminal input mvn -v command I see:
-bash: mvn: command not found
When I input $MAVEN_HOME I see:
: No such file or directory/Path/Maven/maven_3.3.9
If I use echo $MAVEN_HOME command I see:
/Users/{user}/Documents/Path/Maven/maven_3.3.9
If I input this mvn I see:
-bash: mvn: command not found
JDK on Mac - $JAVA_HOME command in Terminal:
-bash: /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home: is a directory
Can you help me please to understand where I missed.
Thank you very much for your answers, I fixed my problem just like that:
export PATH=/Users/{user}/Documents/Path/Maven/maven_3.3.9/bin:$PATH
After that everything worked as expected.
If you think my method is not good, please tell me why?
Since it is a maven 2+, export M2_HOME (see "What is the difference between M2_HOME and MAVEN_HOME")
And double check what echo $PATH returns after sourcing the .bashrc.
Make sure it:
includes $M2_HOME/bin
ls $M2_HOME/bin does exists.
Check this
1) Review your path, I think you are missing '$' character right before {user}
2) Review execution permission for 'maven_3.3.9/bin/mvn'
3) Make sure you are using Bash as Unix shell (and not zsh or another)
echo $SHELL
# output should look like: '/bin/bash'
4) If you are using bash then add maven's ENV variables to the file ~/.bashrc (or ~/.zshrc if you are using zsh)
5) 'source' your configuration
source ~/.bashrc
Notes
I recommend understand differences between .bashrc and .bash_profile: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
If you want to keep your configuration on .bash_profile then just rebooting your system should be enough (to start a login shell which load .bash_profile)
This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 5 years ago.
I tried installing Anaconda to get many python packages at once but had some issues with python IDLE where it said No package found so had to manually set the path in ~/.bashrc.
Once I set the path in ~/.bashrc the IMPORT ERROR in python IDLE was solved but I'm unable to use commands on terminal now.
I'm getting this error all the time.
sid#sids-ubuntu:~$ ls
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found
sid#sids-ubuntu:~$ sudo
Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found
sid#sids-ubuntu:~$ mkdir aa
Command 'mkdir' is available in '/bin/mkdir'
The command could not be located because '/bin' is not included in the PATH environment variable.
mkdir: command not found
I did export PATH=/usr/bin:/bin to find out my $PATH and content of /etc/environment. It seems both are different.
sid#sids-ubuntu:~$ export PATH=/usr/bin:/bin
sid#sids-ubuntu:~$ echo $PATH
/usr/bin:/bin
sid#sids-ubuntu:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Doesn't Ubuntu look for $PATH in /etc/environment?
If yes, what could be the reason my $PATH is different from /etc/environment? and please help me fix it!
If not, where does Ubuntu look for $PATH? please help me fix it!
Be aware that your /etc/environment is only re-read at reboot.
When you want to change your path, be sure to include the existing part as well. To do that, add $PATH in the new path definition.
export PATH="$PATH:/usr/bin"
Looking at your problems, adding the $PATH in your ~/.bashrc should do the trick. If not, open a new terminal and show us the output of
echo $PATH
When adding some directory to PATH it's good idea not to overwrite previous value, just append desired directory (e.g. $HOME/bin), in your ~/.bashrc add at the end line (and remove any previous tampering with PATH)
export PATH="$PATH:$HOME/bin"
and run:
source ~/.bashrc
(or just open new session of terminal).
PATH is an environment variable, and therefore it is not looked up in any file.
There are several files which are sourced when bash is invoked (see the section named INVOCATION in the bash man page), and while sourcing these files, the environment variable PATH can be set, respectively manipulated. Note that .bashrc is not always processed; please read the bash man-page carefully to understand, which files are included under which condition.
According to this mobilefirst tutorial, it mentioned:
You must have the JAVA_HOME environment variable set to your JDK directory.
For example:
Mac OSX: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
I've added this 2 lines in .bash_profile:
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export PATH=$PATH:$JAVA_HOME/Contents/Commands
Is this correct?
Thanks.
in .bash_profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.xx/Contents/Home
Adding the below answer to help those who are looking for step by step instructions on how to setup Java_Home on a Mac.
Determine whether Java is installed by using the command below:
which java
You will something like this - /usr/bin/java
Next Step will be to determine the version of Java Installed by using the command below:
java -version
You will see something like java version "1.8.0_131"
Next step will be to get the location where the Java is installed:
cd /Library/Java
Under the Java folder, select the folder with the version that was displayed earlier:
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
Next check if Java_Home is setup to the correct location:
echo $JAVA_HOME
It will result in blank output if it is not already setup. If it returns the location, check if it points to the correct folder.
You can add or update the Java_Home using the below commands:
vi ~/.bash_profile
Navigate to the end of the file by pressing "Shift + g".
Now press "i" to get to insert mode.
Add the below lines in the bash_profile after replacing the path to the java home directory on your mac
# Setting Java_Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
Save this by pressing Esc followed by ":wq!"
Finally open a new terminal window and test the variable is setup correctly:
echo $JAVA_HOME
It should return the Java_Home path setup
If your default terminal is /bin/zsh (Z Shell) like in my case, then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
After saved the content into env file, restart terminal and call following commands:
echo $JAVA_HOME
It should display the full Java path.
Just a note to say this still works in OpenJDK version 11. As shown in the original question the java_home utility lives in /usr/libexec, which might not be on your $PATH. You can run the command directly in a terminal window, here's sample output too:
$ /usr/libexec/java_home -v 11
/Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
And set JAVA_HOME to that value. Even better, wire your shell script's dot files as suggested in the original question by #user1872384, because that way your environment automatically keeps up with JDK upgrades as you install them.
I'm trying to set up tomcat server and I am using the instructions from a website that has instructed me to
# Execute the Tomcat startup script
./startup.sh
but when i enter the ./startup.sh command i get an error
Cannot find /Library/Tomcat/Home/bin/setclasspath.sh
but the setclasspath.sh is there (see screenshot below):
What am i doing wrong????
now i cannot cd to Home (see screenshot below):
here is the path info:
I had same problem on my mountain lion machine and I use this command :
$ unset CATALINA_HOME
and after that it solved my problem.This command will unset the environmental variable CATALINA_HOME.
just run:
$ unset CATALINA_HOME
in Terminal, and it works again.
Please RESET the CATALINA_HOME to point to correct path. That should resolved the problem.
for example; currently it might be at "/usr/share/tomcat6/" but you need to verify & point till the correct directory like "/usr/share/tomcat6/apache-tomcat-6.0.37/"
Its because of permission, you can run this using root
$ sudo pathtotomcat/bin/./startup.sh
I too had similar issue and I am able to resolve it by simply changing the file permission of tomcat folder . Make it read and Write for everyone. And sh startup.sh command would work fine with Tomcat/7.0.34
I got this solution from here
To make all scripts runnable:
sudo chmod +x /Library/Tomcat/bin/*.sh
I hope it solves your issue too.
The answer of ali is good, but for some reason I also needed to open .bash_profile and comment out CATALINA_HOME
This happens almost definitely because of incorrect value of CATALINA_HOME environment variable in your current shell. In my case for example I had an older tomcat install that I removed and installed another version but forgot to change the env var set in .bash_profile. So any of the methods suggested which remove the var will work. If you have CATALINA_HOME set in .bash_profile, remove it. unset CATALINA_HOME would work too but if its in profile, it will again be set when you open a new shell.
Although all mentioned answers look fine it's a good idea to be aware the main reason.
Somewhere on your operating system, a file is setting environment variables for your operating system, one of those variable names is CATALINA_HOME which is pointing to an address or path. when you attempt to run ./startup.sh or catalina.sh run, these command needs the CATALINA_HOME which is set by your operating system and will override the default CATALINA_HOME of tomcat configuration. (You may have used tomcat and set this variable before and now you forget it)
So the main solution is to edit that special file and it really depends on operating system. In my case, Fedora, two files are candidate one of them is ~/.bashrc and another one is /etc/profile. After editing them you need to source them or log out and then log in (On OS X I think it should be in /Users/username/.bash_profile file).
of course unset CATALINA_HOME command works but after closing and opening a new terminal, again you need to use this command due to refreshing.
U need to set two lines at two places
path details
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export CATALINA_HOME=/opt/tomcat/apache-tomcat-7.0.90
put this path at the end of the lines
files that you want to edit
vi ~/.bashrc
vi ~/.bash_profile
./shutdown.sh
./startup.sh
its works for me