Can I make a entirely homebrew D&D campaign? Or do I have to follow the books for D&D?
There are two types of books for D&D: rulebooks, and modules. Rulebooks like Player’s Handbook, Dungeon Master’s Guide, and Monster Manual basically are the game; without at least the core rules, you have to make up how everything works yourself and you’re not really playing “Dungeons & Dragons” per se. (Instead, you’re playing in a homebrew RPG system, or playing freeform, that is, without rules. Both are entirely valid and we take questions about these activities, but if you call them “Dungeons & Dragons” people will get confused.)
There are core rulebooks (e.g. Player’s Handbook, Dungeon Master’s Guide, and Monster Manual) and supplements (e.g. Tasha’s Cauldron of Everything). The core books are usually the bare minimum; supplements are optional. (It is possible to play without the Dungeon Master’s Guide or Monster Manual, but it can be hard, especially if you are new.)
The other books, modules, contain premade adventures like Tyranny of Dragons or Curse of Strahd. You need them to play those adventures, but you don’t need to play those adventures. You can make up your own adventure, even your own world, and just play with the rulebooks. That is definitely still D&D—in fact, traditionally, it’s the default and norm.
Even if you do run one of those adventures, they will encourage you to—and in practice, you will have to—customize them for your group. It is very rare—and almost never a good idea—to run an adventure exactly as printed, and even the adventures themselves will tell you so.
It’s your choice
You can make an entirely homebrewed campaign using the DnD system if you want to. If you’re making a campaign, everything is your decision. DMs add homebrewed rules, monsters, classes, etc all the time. The core books (Player’s Handbook, Dungeon Master’s Guide, Monster Manual) are there to help you build characters, make rules, and they give you the basics of the DnD system. The Dungeon Master’s Guide has a section on building monsters, classes, player races and magic items, that can really help if you want to make a homebrewed campaign, especially as a new DM.
In essence what you are doing is playing "play pretend", just like you did when you were a kid. You imagine a world, and are pretending to be in it. Of course, to make it a game suitable for multiple players you want some structure in the form of rules. You can choose to make those rules up yourself, or you can use the rules someone else has written. (e.g. one or more of the D&D books, but there's plenty others). After that, you will want some challenges for you and your players: monsters! You can make them up yourself, or you can find them in books written by others. (e.g. Monsters Manual for D&D) Then, you want a world to play in, accompanied by a story. Same here: you can make a world and a story up yourself, or you can consult a book that someone else has written for you. (E.g. Lost Mines of Phandelver (LMOP))
You have the choice to do it yourself or to consult something else in pretty much every step of the game. You can also mix. E.g. use the rules from the PHB, but with homebrew changes. Or use the LMOP campaign, but with a big flying gummybear instead of a dragon. It's all up to you and your imagination.
You can do both
My recommendation for new DMs (and even some seasoned ones) is to run a short low level module set in a setting that you and the players find interesting and then if the campaign goes well you can just keep playing with the same characters in the same setting.
This has several advantages:
- If this is your first time DMing a lot of the work has been done for you by the writers of the module.
- It will give you and your group a chance to see how well you mesh. You may find that you have a problem player, or the group doesn't really work well together IRL. That's fine.
- You can drop plot hooks into the story, and many modules will have plot hooks with suggestions for how to develop them.
- If someone wants to change characters the end of a module is a great time, and if you have new players they may not like their character as much as they thought they would.
Not every module has a concise description of how many levels are expected to be gained during the module, so you might have to do a little digging, but I'd aim for one that brings the PCs from 1-3 or 1-5.
Note also some modules may say "This is an adventure for a party of level 1 to 3" meaning you could start with level 1 or level 3 characters, not that the characters are expected to level up twice during the module.