CAMP HILL, Pa. — Rite Aid is expanding from running drugstores into managing pharmacy benefits with a planned, $2 billion purchase of EnvisionRx.

Shares of the nation’s third-largest drugstore chain climbed more than 7 percent premarket trading.

The company said it will pay about $1.8 billion in cash and $200 million in stock for EnvisionRx, a pharmacy benefit manager, or PBM, owned by the investment firm TPG.

PBMs run prescription drug plans for customers like employers and insurers. They process mail-order prescriptions and handle bills for prescriptions filled at retail pharmacies. EnvisionRx also offers services in a growing area for prescription drug spending, specialty pharmacy, and a national Medicare prescription drug plan.

Rite Aid, which does not have a PBM business, will enter a market dominated by large players like Express Scripts Holding Co. and rival drugstore operator CVS Health Corp.

Rite Aid is based in Camp Hill, Pennsylvania, and runs 4,569 drugstores, a total that trails Walgreen Co. and CVS Health. EnvisionRx is based in Twinsburg, Ohio.

The EnvisionRx deal comes nearly two months after Rite Aid said its fiscal third-quarter earnings jumped 47 percent in a performance that trumped Wall Street expectations, and the drugstore chain hiked its annual forecast after cutting it for two straight quarters.

The boards of directors for both companies have approved the EnvisionRx deal, which is expected to close in September.

Rite Aid shares rose 7.3 percent, or 55 cents, to $8.13 in premarket trading about 30 minutes before the stock markets open.