This question is analogical to the question 'how do we abandon the desire to abandon all desire?'
The answer to these questions is like this:
"'This body comes into being through craving. And yet it is by relying on craving that craving is to be abandoned.' Thus was it said. And in reference to what was it said? There is the case, sister, where a monk hears, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now.' The thought occurs to him, 'I hope that I, too, will — through the ending of the fermentations — enter & remain in the fermentation-free awareness-release & discernment-release, having known & realized them for myself in the here & now.' Then he eventually abandons craving, having relied on craving. 'This body comes into being through craving. And yet it is by relying on craving that craving is to be abandoned.' Thus was it said. And in reference to this was it said.
"'This body comes into being through conceit. And yet it is by relying on conceit that conceit is to be abandoned.' Thus was it said. And in reference to what was it said? There is the case, sister, where a monk hears, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now.' The thought occurs to him, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now. Then why not me?' Then he eventually abandons conceit, having relied on conceit. 'This body comes into being through conceit. And yet it is by relying on conceit that conceit is to be abandoned.' Thus was it said, and in reference to this was it said. - AN 4.159
As to how to do, by developing the four frames of mindfulness, the four right exertions, the four bases of power, the five faculties, the five strengths, the seven factors of awakening, the noble eightfold path.
Here is on attachment to Dhamma:
Monks, I will teach you the Dhamma compared to a raft, for the purpose of crossing over, not for the purpose of holding onto. Listen & pay close attention. I will speak."
"As you say, lord," the monks responded to the Blessed One.
The Blessed One said: "Suppose a man were traveling along a path. He would see a great expanse of water, with the near shore dubious & risky, the further shore secure & free from risk, but with neither a ferryboat nor a bridge going from this shore to the other. The thought would occur to him, 'Here is this great expanse of water, with the near shore dubious & risky, the further shore secure & free from risk, but with neither a ferryboat nor a bridge going from this shore to the other. What if I were to gather grass, twigs, branches, & leaves and, having bound them together to make a raft, were to cross over to safety on the other shore in dependence on the raft, making an effort with my hands & feet?' Then the man, having gathered grass, twigs, branches, & leaves, having bound them together to make a raft, would cross over to safety on the other shore in dependence on the raft, making an effort with his hands & feet. [7] Having crossed over to the further shore, he might think, 'How useful this raft has been to me! For it was in dependence on this raft that, making an effort with my hands & feet, I have crossed over to safety on the further shore. Why don't I, having hoisted it on my head or carrying it on my back, go wherever I like?' What do you think, monks: Would the man, in doing that, be doing what should be done with the raft?"
"No, lord."
"And what should the man do in order to be doing what should be done with the raft? There is the case where the man, having crossed over, would think, 'How useful this raft has been to me! For it was in dependence on this raft that, making an effort with my hands & feet, I have crossed over to safety on the further shore. Why don't I, having dragged it on dry land or sinking it in the water, go wherever I like?' In doing this, he would be doing what should be done with the raft. In the same way, monks, I have taught the Dhamma compared to a raft, for the purpose of crossing over, not for the purpose of holding onto. Understanding the Dhamma as taught compared to a raft, you should let go even of Dhammas, to say nothing of non-Dhammas." - MN 22