The barrel is one of the most critical parts of any firearms. Maybe you want to do a gun with a 3D printer, or start from a blank/disabled weapon: you will need a proper barrel. I'm not an expert, but I'll share all the knowledge I have.
The core: hydraulic pipe
The basis of our barrel will be a seamless steel pipe. You can buy them in several places, even there are pipes sold as "explosion-proof" whose objective is, in fact, to become a firearm barrel.
When buying one, we should look at:
Length: minimum, we need the intended barrel length. The rest will be cut off.
Inner diameter: the closest one we need for our intended caliber, such as 9 mm for 9mm parabellum or .380 ACP.
Outer diameter: with the inner diameter, this will tell us the wall thickness. 2.5 mm thickness is good enough for 9mm. Larger calibers need thicker walls to stand the pressure.
Steel pipe cutter
With this little tool you can cut your pipe to the desired length, and you will get a clean cut.
Adjustable reamer
When you buy a pipe with a 9 mm ID, you'll find that a 9mm bullet won't go go through. You need to wide the hole a little more, something like 9.03-9.04 mm. An adjustable reamer with the correct reaming range will do the trick. For example, a 8-9.25 mm reamer in this case. If your pipe is very long and the reamer short, you'll need to extend the reamer handle with a tool, you can even improvise one gluing the end of the reamer with a pipe using epoxy resin.
Tip: a digital caliper is very useful to know the exact diameter you are getting, and it's a cheap tool.
Chambering the barrel
You need to chamber one end of the tube in order to fit the bullet case. For pistols, it's usually easy. For example, for .380 ACP, is just reaming the first 17 mm of the tube with a 9.5 mm reamer. Other features depend on your gun characteristics: making a slot in one side for the extractor pin, or sanding the bottom to make the ramp. A Dremel is what you need here.
For long guns, a chamber reamer is required. It's easy to get, but quite expensive.
Rifling button and ejector pin
Without rifling, you will have a smoothbore barrel. The bullet will display erratic behaviors, rifling your barrel is highly recommended. Get a rifling button for the desired caliber, an ejector pin and pass the rifling button through your pipe with a hammer. Of course, if you have an hydraulic press, use it.
This is what you need to make a proper barrel. Don't forget to clean it before testing it in order to remove any debris. Always start with low loads to detect any malfunction.