MIT开源协议详解 协议详解
# MIT 协议详解
# 一、为什么先讲 MIT
MIT 是 GitHub 上使用率最高的开源协议,React、Vue、jQuery、Node.js、Ruby on Rails 都用它。如果你只打算了解一种协议,就选 MIT。
它的设计哲学是:我给你代码,你随便用,只需要保留我的名字。
# 二、完整协议文本解读
MIT 只有两段话,却是最精妙的开源法律文本。逐句拆解:
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 2.1 授权条款(第一段)
"Permission is hereby granted, free of charge..."
这一长句的核心:免费授予你以下所有权利:
| 权利 | 含义 |
|---|---|
| use | 使用软件 |
| copy | 复制软件 |
| modify | 修改源代码 |
| merge | 合并到其他软件 |
| publish | 公开发布 |
| distribute | 分发软件 |
| sublicense | 再授权(你可以用 MIT 协议再授权给别人) |
| sell | 售卖软件(可以直接卖钱) |
| permit others | 允许别人也做以上事情 |
关键点:可以商用、可以闭源、可以卖钱、不用回馈作者。 你拿 MIT 代码写了个软件卖了 100 万,不需要给原作者一分钱。
# 2.2 条件条款(第二段)
"The above copyright notice and this permission notice shall be included..."
唯一的条件:保留版权声明和许可声明。实践中就是:
- ✅ 保留项目根目录的 LICENSE 文件
- ✅ 如果是网页/App,在"关于"页面列出版权和协议
- ✅ 如果是 SDK/库,在文档中注明基于 MIT 协议
# 2.3 免责声明(第三段)
"THE SOFTWARE IS PROVIDED 'AS IS'..."
"按原样提供":作者不提供任何保证。软件出事不负责、有 bug 不负责、导致损失不负责。
这也是为什么大公司采用 MIT 库时,仍然需要大量测试——协议本身不承担任何责任。
# 三、实践操作
# 3.1 为自己的项目添加 MIT
# 在项目根目录
cat > LICENSE << 'EOF'
MIT License
Copyright (c) 2025 杨充
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
EOF
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// package.json
{ "license": "MIT" }
2
# 3.2 使用 MIT 库时需要做什么
// 方式一:在代码头部加注释
// This project uses React - Copyright (c) Meta Platforms, Inc.
// Licensed under the MIT License. See https://github.com/facebook/react/blob/main/LICENSE
// 方式二:在 NOTICE 文件中汇总
// 项目根目录 NOTICE:
// This product includes software developed by:
// - React (MIT) - https://reactjs.org
// - Vue.js (MIT) - https://vuejs.org
2
3
4
5
6
7
8
9
# 3.3 MIT 项目的真实案例
| 项目 | 如何遵守 MIT |
|---|---|
| React | LICENSE 文件 + 每个源文件头部有 Facebook 版权注释 |
| Vue.js | 根目录 LICENSE + package.json "license": "MIT" |
| jQuery | LICENSE.txt + 下载页注明协议 |
# 四、MIT vs 其他宽松协议
| MIT | BSD 2-Clause | BSD 3-Clause | Apache 2.0 | Unlicense | |
|---|---|---|---|---|---|
| 可商用 | ✅ | ✅ | ✅ | ✅ | ✅ |
| 可闭源 | ✅ | ✅ | ✅ | ✅ | ✅ |
| 需署名 | ✅ | ✅ | ✅ | ✅ | ❌ |
| 禁止背书 | ❌ | ❌ | ✅ | ✅ | ❌ |
| 专利授权 | ❌ | ❌ | ❌ | ✅ | ❌ |
| 免责声明 | ✅ | ✅ | ✅ | ✅ | ❌ |
# 五、常见问题
Q: MIT 允许我收费出售吗? A: 允许。"sell" 明确写在了授权条款里。
Q: 我修改了 MIT 代码,可以把修改部分闭源吗? A: 可以。MIT 不要求你开源修改。
Q: 我需要把 MIT 协议文本放在产品的每个页面吗? A: 不需要。放在根目录 LICENSE 文件里,在"关于"页面提一句即可。
Q: MIT 可以用在公司内部工具吗? A: 可以,内部使用不触发任何条件。
# 六、总结
MIT 是"三无协议"——无传染性、无专利博弈、无回馈义务。选择 MIT 就是选择"让尽可能多的人用我的代码"。
🏃 下一篇:Apache 2.0 详解——当你需要专利保护时,Apache 2.0 是 MIT 的最佳替代。