Open source
Open-source licences explained: MIT, Apache, GPL and how to choose
Permissive or copyleft? Learn what MIT, Apache 2.0, GPL, LGPL and MPL actually require, how licences mix in one project, and how to pick one for your own code.

Open-source licences are the legal terms that let people use, change and share code, and they fall into two broad families: permissive licences such as MIT and Apache 2.0, which ask little more than credit, and copyleft licences such as the GPL, which require changes to be shared under the same terms. Code with no licence at all is not open source, however public it is.
This guide explains what the common licences require, how they differ, what happens when you combine code under different licences, and how to choose one for a project of your own.
Why does code need a licence at all?
In most countries, code is protected by copyright automatically the moment it is written. Without permission, nobody else may legally copy, modify or distribute it. A licence is that permission, granted in advance to everyone who follows its conditions.
That is why publishing code on the internet without a licence does not make it open source. Others can read it, but strictly speaking they cannot reuse it. If you want people to use your code, add a licence file, usually called LICENSE, to the root of the project.
What are permissive licences?
Permissive licences let anyone do almost anything with the code, including using it in closed-source commercial products, as long as they keep the copyright and licence notice. They are popular for libraries because they remove friction for adoption.
The main ones you will meet:
- MIT: very short. Keep the copyright and licence notice; no warranty is given.
- BSD 2-clause and 3-clause: similar to MIT; the 3-clause version also forbids using the authors' names to endorse derived products.
- Apache 2.0: permissive, but longer and more explicit. It includes an express patent grant from contributors, requires you to note significant changes, and handles NOTICE files.
- ISC and zlib: short permissive licences used by some projects.
Publishing code without a licence does not make it open source.
What is copyleft, and how does the GPL work?
Copyleft uses copyright to keep software open. If you distribute a modified version or a program that includes copyleft code, you must release the source of that work under the same licence. The aim is that improvements stay available to everyone.
The GNU General Public License (GPL) is the best-known copyleft licence. Version 2 is used by the Linux kernel; version 3 adds terms on patents and on devices that block users from installing modified software. The key trigger is distribution: if you use GPL software privately or inside your company without distributing it, you do not have to publish your changes.
The GNU Affero GPL (AGPL) closes what some see as a loophole. If users interact with modified AGPL software over a network, such as a web service, you must offer them the source code too, even though you never handed them a copy.
What are weak copyleft licences?
Between permissive and strong copyleft sit 'weak copyleft' licences. They require you to share changes to the licensed code itself, but not to the larger program that uses it.
The GNU Lesser GPL (LGPL) is designed for libraries: you can link an LGPL library into a closed-source application, provided users can replace the library with a modified version. The Mozilla Public License 2.0 (MPL) works file by file: changes to MPL-licensed files must be shared, but your own new files can use any licence. Both are common in projects that want improvements returned without scaring away commercial users.
What happens when you mix licences in one project?
Most real projects include dependencies under several licences. Permissive code can generally be included in projects under almost any licence, including the GPL. Strong copyleft code is more demanding: including GPL code in your distributed program usually means the combined program must be released under the GPL.
Some licences are incompatible. For example, Apache 2.0 code can be combined with GPLv3 code, but not with GPLv2-only code, according to the Free Software Foundation's analysis. Before adding a dependency, check its licence and how it combines with yours. Many package managers and code scanning tools can list the licences of everything in a project.
How do you choose a licence for your project?
Start from what you want to happen to your code. These rules of thumb cover most cases:
- You want maximum adoption, including in commercial products: MIT or Apache 2.0.
- You want a patent grant and clearer terms for companies: Apache 2.0.
- You want all modified versions to stay open: GPLv3.
- You run a network service and want hosted modifications shared: AGPLv3.
- You want a library that closed apps can use, but changes to it shared: LGPL or MPL 2.0.
- You are joining an existing ecosystem: use the licence most common in it, to make reuse easy.
How do you apply a licence correctly?
Copy the full, unmodified licence text into a LICENSE file in your repository and fill in the year and copyright holder where the template asks. Many projects also add a short licence header or an SPDX identifier, such as 'SPDX-License-Identifier: MIT', at the top of each source file, which tools can read automatically.
Avoid writing your own licence or editing a standard one. Custom terms create uncertainty, and companies often avoid code with unfamiliar licences. If you have specific legal concerns, such as patents or a commercial strategy, talk to a lawyer who knows software licensing.
Frequently asked questions
Can I use MIT-licensed code in a commercial product?
+
Yes. The MIT licence allows commercial use, modification and redistribution, including in closed-source products. You must keep the copyright and licence notice with the code.
Does using GPL software make my code GPL?
+
Only if you distribute a program that includes or is derived from GPL code. Using GPL tools, such as a GPL compiler or editor, does not affect the licence of the code you write with them.
What is the difference between MIT and Apache 2.0?
+
Both are permissive. Apache 2.0 is longer and adds an explicit patent licence from contributors, plus rules about notices and marking changes. MIT is shorter and says nothing specific about patents.
What happens if a project has no licence?
+
By default, copyright law reserves all rights to the author, so you have no permission to copy or modify the code. You can ask the author to add a licence.
What is an SPDX identifier?
+
SPDX is a standard list of short identifiers for licences, such as MIT, Apache-2.0 and GPL-3.0-or-later. Putting one in each file or in package metadata lets tools detect licences reliably.
Can I change the licence of my project later?
+
You can relicense code you own. For code contributed by others, you generally need their agreement, unless they signed an agreement allowing relicensing. Earlier releases remain available under their original licence.
Pick the licence that matches what you want others to do with your work, add the unmodified text to your repository, and check the licences of what you depend on. That covers most open-source licensing questions.
How we research: Guides are written from established sources and checked for accuracy. They are general information, not professional advice.
Written by
Cursorlane Editorial Team
Software & tools
Our writers are developers and heavy software users who test what they write about and update guides when the tools change.


