Published in Realtor.com, July 28, 2016

Rent is expensive. And sometimes that means you’ve got to take on a roomie in order to pay the monthly bills. But what happens if your roommate turns to the dark side—i.e., doesn’t pay rent, invites his entire rugby team over every night for drinks until dawn, or otherwise makes your home environment too hard to handle? Can you evict your roommate, or are you stuck with this person for good?

To get the lowdown on what’s legal, we talked to Robert Pellegrini, president of PK Boston, a real estate and collections law firm with offices in Boston.

Here’s what renters can do when a roommate relationship heads south.

If your roommate’s not paying rent

This one seems clear-cut, but it can get messy if the terms of your payments aren’t carefully spelled out in your lease. For instance, if the rent is $1,000 per month but the lease doesn’t break it down between the two tenants, then you’re jointly responsible for paying it. So if your roommate falls short, “both of you would probably get evicted if rent is not met, even if you’ve paid your half,” says Pellegrini.

One smart preventive measure is to ask your landlord to give out separate leases to each tenant, suggests Pellegrini. That way, if your roommate violates the terms, you are in no way responsible for his actions. And even if you are both on the same lease, “you could probably talk with the landlord and make alternate arrangements—in other words, get your roommate evicted and then re-sign a new lease with just you, or get another tenant in the meantime.”

If your roommate’s on the lease

If your roommate is doing something illegal—like doing drugs, being violent, or threatening you—it’s quite easy to get him out by filing a police report followed by a restraining order. But if your roommate is just annoying, your job becomes more challenging, especially if his name’s on the lease.

Landlords don’t like to get involved in roomie squabbles; however, if he’s racking up an impressive list of egregious violations, you might be able to get your landlord on your side and move to evict him (especially if you can prove the violations go against the parameters of the lease).

So keep a written list, and remember the complaints must be more substantial than “Leaves dirty dishes in the sink for a week” (personal roommate issues) and more like “Has her boyfriend and his relatives staying with us every night” (potential lease violation).

If your roommate’s on a sublease

When taking on a roommate who is not going to be on the lease, it’s a good idea to make sure you ask permission from your landlord, who will probably provide you with a sublease form, or you may draft a sublease with the parameters you desire.

Here are some things Pellegrini suggests putting on a sublease: a security deposit, whether pets are allowed, how many guests the roommate can have and for how long, what alterations they can make to the space, a late fee for rent, who pays utilities, and how many keys will be made. Also make sure that you retain the right to terminate the sublease with a reasonable clause (e.g., 30 days’ notice). Have a lawyer look over any sublease agreements and/or have it notarized. Then if your roomie violates any of the terms, you can evict her—but you need to go through the proper steps, just as a landlord would.

If your roommate’s not on any lease

Sorry, just because your roommate is not “officially” on any lease doesn’t mean you can just change the locks and throw his clothes out the window.

“In that case, the roommate could go right down to the police station and they’d most likely help the roommate regain access to the apartment,” says Pellegrini. That’s because anyone who moves into an apartment acquires some homestead rights, which means you can’t just rip the roof off from over their heads.

“You would have an uphill battle in court to evict the roommate if he’s otherwise abiding by the law,” says Pelligrini. In this case, you would have to gain your landlord’s cooperation in order to evict your roommate, because as a renter you don’t have the rights of a property owner to evict tenants.

If your roommate refuses to leave

If you have successfully gotten your landlord on board with the eviction and your roommate still won’t go, you may need to file a petition with your municipal housing court. In New York City, for example, there is a website where you can get the official forms for a termination notice as well as a petition to remove the person if she becomes what is known as a “holdover roommate” (i.e., someone who has been served a notification to vacate but refuses). All states should have similar services, but keep in mind you may be in for a drawn-out court case before you can get the roommate out—which can make for one heck of an awkward living situation.