Related
I used miniconda2 but I had to upgrade to miniconda3. However, how can export miniconda2's environments to miniconda3?
Thank you in advance,
UPDATE
I found here the below script:
for env in $(conda env list | cut -d" " -f1); do
if [[ ${env:0:1} == "#" ]] ; then continue; fi;
conda env export -n $env > ${env}.yml
done
It only picks up the new miniconda3 environments and not the old miniconda2 which are located in a different folder.
> ls -1 /work/miniconda2/envs/
3d-dna
abyss
afterqc
busco4
...
(base)> conda activate /work//miniconda2/envs/busco4
(busco4)>
How can I modify the above script to export from miniconda2 folder?
I'm having a hard time finding a conda YML file that's that old. There's no foolproof way that I'm aware of but here is a way that should satisfice the solution.
Note: This is for linux or mac; you can use findstr for Windows. Or PowerShell.
From your environment:
conda env export --from-history | grep -v "prefix" > your_environment_name.yml
You can view the contents with cat environment.yml. This gives you the libraries -- but not the dependencies -- and no version numbers for anything. I did that because sometimes a dependent library will get dropped for some reason or another. You may need to modify this with the new version of python you want.
I think this works better than conda env export | cut -f 1 -d '=' | grep -v ^prefix because, again, sometimes a dependency will get dropped.
From there
conda env create -f your_environment_name.yml -p /home/user/anaconda3/envs/your_environment_name
An alternative approach here is to add the previous Miniconda2 package cache (/work/miniconda2/pkgs) and environments directory (/work/miniconda2/envs) to the pkgs_dirs and envs_dirs Conda configuration settings. That way you can simply continuing having them available without having to archive and recreate. There are some details in this answer.
You may need to add back the Miniconda3 locations after this if you would like them to continue to be defaults.
Also, because you installed multiple copies of Conda, you should probably check your ~/.bashrc (and/or ~/.bash_profile) file to remove any previous sections from conda init left by the other version.
E.g. on a fresh ubuntu machine, I've just run sudo apt-get git, and there's no completion when typing e.g. git check[tab].
I didn't find anything on http://git-scm.com/docs, but IIRC completion is included in the git package these days and I just need the right entry in my bashrc.
On Linux
On most distributions, git completion script is installed into /etc/bash_completion.d/ (or /usr/share/bash-completion/completions/git) when you install git, no need to go to github. You just need to use it - add this line to your .bashrc:
source /etc/bash_completion.d/git
# or
source /usr/share/bash-completion/completions/git
In some versions of Ubuntu, git autocomplete may be broken by default, reinstalling by running this command should fix it:
sudo apt-get install git-core bash-completion
On Mac
You can install git completion using Homebrew or MacPorts.
Homebrew
if $BASH_VERSION > 4: brew install bash-completion#2 (updated version)
Pay special care which version of bash you have as MacOS default ships with 3.2.57(1)-release.
add to .bash_profile:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
For older versions of bash: brew install bash-completion
add to .bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
MacPorts
sudo port install git +bash_completion
then add this to your .bash_profile:
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
fi
more info in this guide: Install Bash git completion
Note that in all cases you need to create a new shell (open a new terminal tab/window) for changes to take effect.
i had same issue, followed below steps:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
then add the following lines to your .bash_profile (generally under your home folder)
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
source : http://code-worrier.com/blog/autocomplete-git/
Most of the instructions you see will tell you to download
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
and source that in your bash startup script like .bashrc.
But there is a problem with that, because it is referencing the master branch, which is the latest version of git-completion.bash. The problem is that sometimes it will break because it is not compatible with the version of git you've installed.
In fact, right now that will break because the master branch's git-completion.bash has new features that requires git v2.18, which none of the package managers and installers have updated to yet. You'll get an error unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
So the safest solution is to reference the version/tag that matches the git you've installed. For example:
https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash
Note that it has a v2.17. in the URL instead of master. And then, of course, make sure to source that in the bash startup script.
Ubuntu 14.10
Install git-core and bash-completion
sudo apt-get install -y git-core bash-completion
For current session usage
source /usr/share/bash-completion/completions/git
To have it always on for all sessions
echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc
Just do this in your ~/.bashrc:
source /usr/share/bash-completion/completions/git
Other answers are telling you to install bash-completion, you don't need to do that, but if you do, then there's no need to source the completion directly. You do one or the other, not both.
A more generic solution is querying the system location as recommended by the bash-completion project:
source "$(pkg-config --variable=completionsdir bash-completion)"/git
See https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
You just need to source the completion script
on my ubuntu there is a file installed here:
source /etc/bash_completion.d/git-prompt
you can follow the links into the /usr/lib/git-core folder. You can find there an instruction, how to set up PS1 or use __git_ps1
macOS via Xcode Developer Tools
Of all the answers currently posted for macOS, this is only mentioned in a very brief comment by jmt...
If you already have the Xcode developer tools installed, then you shouldn't need to download anything new.
Instead, you just need to locate the already-existing git-completion.bash file and source it in your .bashrc. Check the following directories:
/Applications/Xcode.app/Contents/Developer/usr/share/git-core
/Library/Developer/CommandLineTools/usr/share/git-core
Failing that, git itself might be able to help you out. When I run git config as follows, git reports a setting which comes from a gitconfig file located in the same directory as my git-completion.bash:
$ git config --show-origin --list
...
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig credential.helper=osxkeychain
...
or you can always brute-force search your machine and grab some coffee:
$ find / -type f -name git-completion.bash 2>/dev/null
Thus, I have the following insertion for my ~/.bashrc:
# Git shell completion and prompt string on macOS
_git_dir="/Applications/Xcode.app/Contents/Developer/usr/share/git-core"
if [ -f "${_git_dir}/git-completion.bash" ]; then
source "${_git_dir}/git-completion.bash"
fi
if [ -f "${_git_dir}/git-prompt.sh" ]; then
source "${_git_dir}/git-prompt.sh"
fi
unset _git_dir
Note that this sources the git prompt-string script as well, since it resides in the same directory.
(Tested in macOS Catalina)
May be helpful for someone:--
After downloading the .git-completion.bash from the following link,
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
and trying to use __git_ps1 function, I was getting error as--
-bash: __git_ps1: command not found
Apparently we need to download scripts separately from master to make this command work, as __git_ps1 is defined in git-prompt.sh . So similar to downloading .git-completion.bash , get the git-prompt.sh:
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
and then add the following in your .bash_profile
source ~/.bash_git
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
export PS1='\W$(__git_ps1 "[%s]")>'
fi
source ~/.bash.git will execute the downloaded file and
export PS1='\W$(__git_ps1 "[%s]") command will append the checkout out branch name after the current working directory(if its a git repository).
So it will look like:-
dir_Name[branch_name] where dir_Name is the working directory name and branch_name will be the name of the branch you are currently working on.
Please note -- __git_ps1 is case sensitive.
Arch Linux
Source /usr/share/git/completion/git-completion.bash in one of the bash startup files.
For example:
# ~/.bashrc
source /usr/share/git/completion/git-completion.bash
You may be able to find the script in other locations like /usr/share/bash-completion/completions/git but these scripts did not work for me.
Mac M1
For those that are using Mac M1 environment, I was able to install via homebrew:
brew install bash-completion
Then added to my ~/.bash_profile or ~/.bashrc (whatever you use):
[[ -r "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh"
You may need to update the version number (1.3_3). You'll just need to look it up in that directory. I would love to know if there's a better way.
Windows
How it works for me finally on Windows 10 command line (cmd):
Install Clink
Copy git-autocomplete.lua file into C:\Users\<username>\AppData\local\clink directory
Restart Windows
Ubuntu
There is a beautiful answer here. Worked for me on Ubuntu 16.04
Windows
Git Bash is the tool to allow auto-completion. Not sure if this is a part of standard distribution so you can find this link also useful.
By the way, Git Bash allows to use Linux shell commands to work on windows, which is a great thing for people, who have experience in GNU/Linux environment.
On Ubuntu 22.04 just add this line at the end of .bashrc or .zshrc
source /etc/bash_completion.d/git-prompt
On Github in the Git project, They provide a bash file to autocomplete git commands.
You should download it to home directory and you should force bash to run it. It is simply two steps and perfectly explained(step by step) in the following blog post.
code-worrier blog: autocomplete-git/
I have tested it on mac, it should work on other systems too. You can apply same approach to other operating systems.
Just put below in the .bashrc and relaunch the terminal. Navigate to Git repo to see the path in the prompt.
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] # \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '
I installed anaconda3 into my home directory. This is what I am seeing within the terminal:
and my .bash_profile looks like this:
export PATH="/Users/spotter/anaconda3/bin:$PATH"
So I don't understand why conda is not being recognized. When I navigate to anaconda3/bin there is a file called conda in there, but even when I try to call it within that pathway it is still not found.
Spotter, your path to conda is incorrect.
I'm on High Sierra MAC OS and just installed Anaconda3 via HomeBrew command. I had issue with running :
conda
It'd also give me:
-bash: conda: command not found
I tried running:
export PATH=~/anaconda3/bin:$PATH
but it needs ENTIRE path. so here are the correct steps:
$ nano ~/.bash_profile
Now export the ENTIRE path, in my case it was:
export PATH=/usr/local/anaconda3/bin:$PATH
Exit out and run:
$ source ~/.bash_profile
Then try:
$ conda
it'll output:
$ conda --version
conda 4.4.10
I had to type source ~/anaconda3/bin/activate.
For anyone that landed here that is using a non-standard shell (zsh for example) the installer 5.3.1 currently changes the bash_profile not the current active default terminal.
Just open ~/.bash_profile, find the block that is added by the installer and copy it into your .zshrc file (if using zsh)
in Mac OS, for conda >4,4, the conventional way of exporting path (export PATH="Users/myuser/anaconda3/bin:$PATH") is NOT recommended anymore. First, see what is error message in your terminal in Mac when you type conda --version. If it says zsh conda not found then you are using ZSH terminal, so modifying any bash file is useless. In this case, you need to edit your .zprofile. on the other hand, if you get error like bash conda not found you edit .bash_profile. Lets, say we have zsh error, then type in terminal:
sudo nano ~./zprofile
located your conda.sh file by searching in your finder. Most probably it is in
~/anaconda3/etc/profile.d/conda.sh
(for me it was like: /Users/hasbah/opt/anaconda3/etc/profile.d/conda.sh, but instead of anaconda3, it might be conda)
then you type in .zhprfile this:
. /Users/myuser/opt/anaconda3/etc/profile.d/conda.sh
conda activate base
then you save (ctrl+X and Y when was asked to save) and restart the terminal.
Now if you type conda --version you will see it.
so, in short:
sudo nano ~/.zproflie
. /Users/myuser/opt/anaconda3/etc/profile.d/conda.sh
conda activate base
save ./zproflie file
close terminal
open new terminal
conda --version
Rather than adding the ~/anaconda3/bin to your PATH, you should add
. ~/anaconda3/etc/profile.d/conda.sh
conda activate base
to your .bash_profile or .bashrc, or type that in a shell, if you don't want it to be activated for each shell. This is the recommended way to activate conda since conda 4.4. See: https://github.com/conda/conda/blob/master/CHANGELOG.md#440-2017-12-20
I'm on Ubuntu 14.04 and I've been trying all possible methods to install Laravel to no avail. Error messages everything I try. I'm now trying the first method in the quickstart documentation, that is, via Laravel Installer, but it says to "Make sure to place the ~/.composer/vendor/bin directory in your PATH so the Laravel executable is found when you run the Laravel command in your terminal." so my question is, how do I do that? This may be a simple question but I'm really frustrated and would appreciate any help.
To put this folder on the PATH environment variable type
export PATH="$PATH:$HOME/.composer/vendor/bin"
This appends the folder to your existing PATH, however, it is only active for your current terminal session.
If you want it to be automatically set, it depends on the shell you are using. For bash, you can append this line to $HOME/.bashrc using your favorite editor or type the following on the shell
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
In order to check if it worked, logout and login again or execute
source ~/.bashrc
on the shell.
PS: For other systems where there is no ~/.bashrc, you can also put this into ~/.bash_profile
PSS: For more recent laravel you need to put $HOME/.config/composer/vendor/bin on the PATH.
PSSS: If you want to put this folder on the path also for other shells or on the GUI, you should append the said export command to ~/.profile (cf. https://help.ubuntu.com/community/EnvironmentVariables).
Detailed instructions:
in your ~/.bashrc add these lines:
export PATH="$PATH:~/.composer/vendor/bin"
Then reload:
source ~/.bashrc
Check if its added correctly:
echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/web/bin:~/.composer/vendor/bin
In Ubuntu 16.04 LTS with composer globally installed, this worked for me.
Edit the .bashrc file in your home directory puting the path to the composer bin folder that is located in /your/home/.config/composer/vendor/bin
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc
If not works, verify the path to the composer bin directory and close and reopen the terminal. Otherwise, try to logoff and login in the Ubuntu.
Also works in ubuntu 18.04. Thanks #chifliiiii for your feedback.
For setting the PATH on Yosemite (OS X 10.10.5), use the command below:
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile
To reload either quit terminal and start up again or use:
source ~/.bash_profile
Helped me, hope it helps someone else out there!
I did all of the above and it didn't work for me.
I just copied this into my terminal and it worked for me.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
my path didn't have /.composer, just /composer so my path was:-
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
This worked for me on ubuntu 20.04
This is for setting PATH on Mac OS X Version 10.9.5.
I have tried to add $HOME because I use user profile :
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
When you do not use user profile:
echo 'export PATH="$PATH:~/.composer/vendor/bin"' >> ~/.bashrc
Then reload:
source ~/.bashrc
I hope this help you.
Open the Mac Terminal:
vi ~/.bashrc
If you haven't used vi, it may look a little funny at first, so enter the following code carefully, in order:
i
export PATH="$PATH:$HOME/.composer/vendor/bin"
PRESS ESC
:
w
PRESS ENTER
:
q
PRESS ENTER
Now you should have returned to the normal terminal view.
Check that composer now has the correct path:
cd ~/.composer
echo $PATH
If you see the path including your file directory, (e.g. /Users/JeffStrongman/.composer/vendor/bin), you're good to go.
cd
Then run your installation. I ran into this problem, while configuring my Mac to use Laravel Valet.
Example (optional)
valet install
For Linux Mint 18: edit ~/.bashrc and add this line to it at the bottom:
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
then resource .bashrc (type in console):
source ~/.bashrc (or close and reopen the terminal)
test it by typing in the console:
echo $PATH
or type in console:
laravel
In case someone uses ZSH, all steps are the same, except a few things:
Locate file .zshrc
Add the following line at the bottom export PATH=~/.composer/vendor/bin:$PATH
source ~/.zshrc
Then try valet, if asks for password, then everything is ok.
add environment variable into bashrc file
For Ubuntu 17.04 and 17.10:
echo 'export PATH="~/.config/composer/vendor/bin"' >> ~/.bashrc
For Ubuntu 18.04
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
to Check environment variable working or not first reload the bashrc file
source ~/.bashrc
if not working any method then First Check Where is install Composer to Check Run This Command :
locate composer -l 1
then Copy Output add output into this line and run again command.
echo 'export PATH="OUTPUTHERE/vendor/bin"' >> ~/.bashrc
After Successfully Laravel Command Work Give a Permission To Parent Folder (for example u are using apache server than give permission to apache web listing directory like that)
sudo chown $USER:$USER -R /var/www/html/
For me in Ubuntu 22.04, this works:
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
Adding export PATH="$PATH:~/.composer/vendor/bin" to ~/.bashrc works in your case because you only need it when you run the terminal.
For the sake of completeness, appending it to PATH in /etc/environment (sudo gedit /etc/environment and adding ~/.composer/vendor/bin in PATH) will also work even if it is called by other programs because it is system-wide environment variable.
https://help.ubuntu.com/community/EnvironmentVariables
MacOS Sierra User:
make sure you delete MAAP and MAAP Pro from Application folder if you have it installed on your computer
be in root directory cd ~
check homebrew (if you have homebrew installed) OR have PHP up to date
brew install php70
export PATH="$PATH:$HOME/.composer/vendor/bin"
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile
source ~/.bash_profile
cat .bash_profile
make sure this is showing :
export PATH="$PATH:$HOME/.composer/vendor/bin"
laravel
now it should be global
The Composer bin directory is set and stored in bin-dir config variable and can be different depending on your setup. Running the command composer global config bin-dir --absolute will tell you the absolute path to your global composer bin directory. Using this command you can modify your .bash_profile to add it to your PATH exactly how it is configured.
# Add Composer bin-dir to PATH if it is installed.
command -v composer >/dev/null 2>&1 && {
COMPOSER_BIN_DIR=$(composer global config bin-dir --absolute 2> /dev/null)
PATH="$PATH:$COMPOSER_BIN_DIR";
}
export PATH
AWS Ubuntu 18.04 LTS
Linux ws1 4.15.0-1023-aws #23-Ubuntu SMP Mon Sep 24 16:31:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc && source ~/.bashrc
Worked for me.
On Fedora:
Some composer bins are not in the .composer directory
So you need to locate them using:
locate composer | grep vendor/bin
Then echo the the part into the .bashrc
echo 'export PATH="$PATH:$HOME/{you_composer_vendor_path}"' >> ~/.bashrc
Mine was "/.config/composer/vendor/bin"
Cheers!
For Ubuntu 16.04
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc
I did this and it works on osx:
lunch your terminal
nano ~/.bash_profile
And paste
export PATH=~/.composer/vendor/bin:$PATH
press control + x
press the y key
press the return / enter key
this is what I added in my .bashrc file and worked.
export PATH="$PATH:/home/myUsername/.composer/vendor/bin"
To solve this problem make sure you find the path of composer.phar first
example mine is something like this
alias composer="php /Users/Your-username/composer.phar"
Go to cd Users > Your user > Command ls and see if composer.phar is there if yes then add the above line to your .bash_profile. Make sure you change the username to your own.
Hope this help you out
I've tried a lot of solutions, but on Ubuntu 20.04 only this worked for me:
export PATH="$HOME/.composer/vendor/bin:$PATH"
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.