Rapper DMX was outfitted with an ankle bracelet and put on 24/7 home detention by a Manhattan federal judge on Friday after twice skipping town without permission and failing multiple drug tests that were part of his bail package on tax charges.

The confinement order came after the rap star, whose name is Earl Simmons, got his bail violation hearing off to a bad start by showing up late in U.S. District Judge Jed Rakoff’s courtroom. His lawyer said he was stuck in traffic on the West Side Highway.

After finally arriving 40 minutes late with a small entourage, wearing a tie-dye Def Leppard T-shirt and sunglasses inside the courthouse, he avoided being remanded to jail and seemed pleased with the outcome when he finally emerged with his ankle bracelet.

“That’s a celebration right there,” he told a photographer who asked how he would celebrate. “Just being in there and being able to walk out.”

Simmons, 46, of Yonkers, was charged in July with hiding income and evading $1.7 million in taxes. He was released on a $500,000 bail package that required him to have someone co-sign his bond, stay in New York and submit to drug testing.

Rakoff said the rapper never got a co-signer, failed 4 drug tests for cocaine, marijuana and opiates, went once to St. Louis — for what he called a family emergency — and once to Chicago without permission, and skipped meetings and lied to pretrial services officers.

advertisement | advertise on newsday

The judge said it was probably more violations in a short period than he had ever seen in his career on the bench. “This gives the court very little confidence that he should be released at all,” Rakoff said.

Simmons’ lawyer, Murray Richman, said his client needed to be out of jail to help prepare his case and to keep supporting his “numerous” children — 15 according to news accounts.

The judge eventually relented, ordering home confinement instead of jail. He said Simmons will only be allowed to go to meetings with his lawyer, and otherwise will need the judge’s permission personally.

“Only if I agree in advance can he even go outside to water the lawn,” said Rakoff, who also ordered Simmons to participate in a drug-treatment program devised by pretrial services officials.

When Simmons left court, he embraced members of his crew and told reporters, “When God is with you, who can be against you?”

Supporters then got into a small shoving match with reporters in an effort to keep them off Simmons’ elevator. Simmons later apologized to one female reporter who was pushed.