1. Use an upper block as Kevin has shown in his photos.
2. Use one of the hinged plastic wrap around receiver clamps.
3. Use one of the rear entry lug wrenches that engages the barrel nut.
4. Hold the barrel in aluminum barrel blocks, as Bolivar pointed out.
All of these require a barrel nut wrench, and the best system to use will depend on how tight the nut is on.
Last upper in the shop came off easily using method 4, although I have the tools for 2 and 3.
Don't do it like someone did on a second hand barrel I bought, using a punch and hammer on the barrel nut teeth. Made a heck of a mess, although the barrel was removed, and the nut is reusable.
If you don't want to invest in the tools, find someone who has them, or take it to a 'smith with the tools.
Some barrel nuts are really tight, to the point that there is real risk of damaging the upper. If it comes to it, one of these cane be cut off. Barrel nuts are cheap, uppers aren't.