On macOS, you can add the following to your .zshrc file.
If you have not, download maven from https://maven.apache.org/download.cgi
# Maven
export PATH=/opt/apache-maven-3.8.3/bin:${PATH} # you could have it in a different directory
To edit .zshrc, you can use an existing text editor such as vim.
$ cd ~
$ vim .zshrc
Use i
to insert the export statements. Once inserted, use esc
to exit insert mode. Then use :wq!
to save and quit the editor. Finally, source the file to see the effects of your new changes.
$ source .zshrc
Now try mvn
and you should see something like this.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.049 s
[INFO] Finished at: 2021-10-11T13:34:20-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
export PATH=$PATH:$M2_HOME/bin
. Notice the$
I added. Also, no need to export; export sets a flag in bash/zsh/etc., and it only needs to be set once. – Handel