No space is needed between the hole and any nearby walls or ceilings.
As the spell description states, Rope Trick opens to an extradimensional space. Extradimensional spaces are outside of normal space and do not occupy any equivalent volume in normal space.
The fact that extradimensional spaces occupy no volume in normal space becomes obvious when you also look at the function of various magical items that uses them. For example, Portable Hole is a handkerchief that you can unfold into a circular sheet and when spread on a solid surface it becomes a 10-foot deep hole. The solid surface can be a table, so you can disappear "into" the table. The entrance generated by the Rope Trick spell is just like a Portable Hole but opened upwards.
You might also find the following unofficial tweet by Jeremy Crawford relevant:
Q: Are extraplanar spaces (e.g. rope trick) considered to be on a different plane, or just a "wrinkle" on the material?
Crawford: An extraplanar space is outside other planes.