Beginning next year, you will have to be 21 years old to buy tobacco products in Massachusetts, including cigarettes and e-cigarettes.

Gov. Charlie Baker signed a bill on Friday raising the age limit from 18 to 21.

"There's more than enough evidence to support ensuring that we have a statewide standard with respect to when the purchase and use of these products would be considered age appropriate," Baker said.

Baker acknowledged that he is typically a supporter of local control. In this case, more than 170 municipalities already raised the tobacco purchase age above 18.

"At this time, it's our view that a statewide approach is perfectly appropriate," Baker said.

The law goes into effect Dec. 31, 2018. Anyone who turns 18 before that date will still be allowed to buy tobacco, as long as there was not a municipal ordinance already in place banning tobacco sales to 19 or 20-year-olds.

Massachusetts will be the sixth state to raise the tobacco buying age to 21.

The law also regulates electronic cigarettes -- raising the age for buying e-cigarettes to 21, prohibiting the smoking of e-cigarettes on school grounds and in nursing homes, prohibiting the sale of vaping products in vending machines, and requiring nicotine and tobacco products to be packaged in childproof containers.

The bill also prohibits the sale of tobacco products in pharmacies or health care facilities.

Rep. Kate Hogan, D-Stow, House chairwoman of the Committee on Public Health, said she started smoking as a teenager. "For me, today means a lot, because it means many kids out there are not going to be smoking as teenagers and not have to go through whatever everyone has to go through when they decide they want to quit smoking," Hogan said.

Sen. Jason Lewis, D-Winchester, Senate chairman of the Committee on Public Health, said the bill will prevent more teenagers from becoming addicted to nicotine and from using e-cigarettes, which he called "an epidemic in our middle and high schools."

According to the American Cancer Society, 95 percent of adults who smoke started smoking before age 21. One goal of raising the age is to keep cigarettes out of high schools.

Public health advocates cheered the move.

Massachusetts Medical Society president Alain Chaoui said many of his patients regret the decision to start smoking at a young age because it is so hard to quit. "By taking steps to restrict access to products we know cause disease and premature death, the Commonwealth acted to protect our children and significantly decreased the chances that their health will one day be compromised by the harmful effects of tobacco use," Chaoui said in a statement.

George Philippides, chief of cardiology at Newton-Wellesley Hospital, said in a statement distributed by the American Heart Association, "Increasing the age of sale for tobacco products to 21 will help counter the tobacco industry's relentless efforts to target youth at a time when many move from experimenting with tobacco to regular smoking."

Matt David, a spokesman for the e-cigarette manufacturer JUUL, said the company supports the bill. "We want to keep JUUL out of the hands of young people, and we believe raising the minimum purchase age is a step in the right direction," David said in a statement.

Attorney General Maura Healey recently launched an investigation into JUUL Labs, alleging that the California-based company's products are marketed to minors.

This story was updated with comments from JUUL.