It is often necessary to use a saw to cut the junction from the joist to which it is attached.
Install recessed lighting junction box.
Electrical codes generally require that all electrical devices and the wiring connections to those devices must be enclosed in an approved electrical box often known as a junction box this metal or plastic box includes a cover to protect the wiring within and protect you from the wiring.
Run nm b cable from the power source to a switch box and then to the first hole allowing at least 18 inches of extra cable to make wiring easy.
Second the original wires removed from the old box will not be long enough to connect directly to the recessed fixture so you will have to install a junction box inside the ceiling.
This rule is demonstrated nicely by wall switches receptacles and standard light fixtures all of.
Take care to avoid damaging wires which can sometimes have a short span making it more challenging to install a new housing.
When installing a recessed light fixture in the location of an existing light fixture you must remove the old fixture and disconnect and remove the wiring as well as the ceiling box.