Im preparing to open source some code Im been working on, and have decided for the GPL2 license. Im wondering what the proper way is to mark code as licensed with this license.

looking at the Linux sourcecode I can see that the GPL2 license is included in the root directory in a "LICENSE" file of some sort. Also, some of the files have some (a paragraph or so) license text at their top, other files just kind of reference in a single comment line which license they use.

is there a best practice for how to mark a file licensed under a particular license?


There are the terms for the license, and some statement that your project is licensed under those terms. The GPL has an appendix "How to Apply These Terms to Your New Programs" that explains how to attach license notices. It suggests but in no way requires that you add the following header to each source file:

one line to give the program's name and an idea of what it does.
Copyright (C) yyyy  name of author

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

(remember to fill in the description, year, and author, and to remove the "or (at your option) any later version" part.)

I would also place similar text into a top-level LICENSE file and put the full terms of the GPL into a COPYING or LICENSE.GPLv2 file. The specifics don't matter as long as it is clear that the copyright holder has issued this license.

  • I see that the Linux kernel is currently recommending inclusion of the //SPDX-License-Identifier: GPL-2.0 line at the top of each file, instead of the GPL2 header text that you mention above (I also found the "How to apply..." section in the full GPL2 text :) ). what do you think about using //SPDX-License-Identifier: GPL-2.0?
    – deepblue
    Jan 7 '19 at 17:15
  • Using SPDX identifiers is cool because that makes the license coverage machine readable. However, most projects have less stringent traceability requirements than the Linux kernel. Importantly, that identifier is just for internal use and not in itself a license grant, unless e.g. the header suggested by the GPL itself.
    – amon
    Jan 7 '19 at 17:22
  • ok. I'll use the GPL license header then, the one suggested in the license. thanks @amon :)
    – deepblue
    Jan 7 '19 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.