mvn install vs mvn deploy
Fast recall
Quick revision
Core answer
Understanding that Maven's deploy is not the same as deploying an application to a server — a very common confusion among freshers
Thinking mvn deploy deploys the application to a production server — it actually deploys the artifact to a Maven repository
Clarify that deploying to servers (Kubernetes, EC2, etc.) is done by different tools like Docker, Kubernetes, or deployment scripts — Maven deploy is only about artifact repositories
Interview-ready guide
Interview answer
The difference between mvn install and mvn deploy is about where your built artifact goes and who can access it.
Install copies your JAR or WAR file to your local Maven repository, which is a directory on your machine at tilde slash dot m2 slash repository. This is really useful when you're working on multiple projects locally and one project depends on another.
For example, if I'm building an order-service that depends on a common-utils library I'm also developing, I'll run mvn install on common-utils first to put it in my local repo, then when I build order-service it can find common-utils as a dependency right there on my machine.
Deploy is different — it uploads your artifact to a remote Maven repository that's shared across your entire team, like Nexus or Artifactory. This is how you make your artifact available to other developers, CI/CD systems, and production environments. Typically deploy happens automatically in your CI/CD pipeline when you merge code.
One really important thing that trips up freshers is the word deploy itself. In Maven, deploy doesn't mean deploying your application to a server like Tomcat or Kubernetes. It only means uploading your JAR to a Maven repository.
Actually deploying your app to a runtime server is done by completely different tools like Docker, Kubernetes, or deployment scripts. Maven deploy is purely about artifact distribution, not application deployment. Another mistake is running mvn deploy from your local machine during development — you almost never want to do this because it pushes artifacts to the shared repository unnecessarily.
Deploy should happen in CI/CD, not on your laptop.
mvn install vs mvn deploy
Direct Answer
mvn install copies the packaged artifact to your local ~/.m2 repository on your machine so other local projects can use it as a dependency. mvn deploy uploads the artifact to a shared remote Maven repository like Nexus or Artifactory for the entire team and CI/CD system to access.
Code Example
<!-- deploy needs a target repository; install needs nothing -->
<distributionManagement>
<repository>
<id>company-releases</id>
<url>https://nexus.company.com/repository/maven-releases/</url>
</repository>
</distributionManagement>
mvn install copies the artifact to ~/.m2; mvn deploy uploads it to the repository above for the whole team.
Common Mistakes & Pitfalls
- Thinking deploy means server deployment: The most common mistake is thinking mvn deploy deploys your application to a runtime server like Tomcat, Kubernetes, or AWS. It doesn't — it only uploads your JAR to a Maven artifact repository. Deploying to servers is done by tools like Docker (docker push), Kubernetes (kubectl apply), or cloud deployment scripts. Maven deploy is purely about artifact repository management.
- Running deploy during local development: Some freshers run mvn deploy from their local machine during normal development, accidentally pushing snapshot versions to the shared repository. This pollutes the repository with unnecessary artifacts and can confuse teammates. Deploy should almost always happen in CI/CD pipelines, not local machines.
- Not configuring distributionManagement: Maven deploy requires a distributionManagement section in your pom.xml specifying the remote repository URL and credentials. Freshers often try to run mvn deploy without this configuration and get confused when it fails. If you're not sure whether your project is configured for deploy, it probably isn't, and you shouldn't be running it.
Check your understanding
Answer these without looking back at the article.
- What is Nexus repository?
- What is a multi-module Maven project?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.