Firearms are not a particularly vital business for Walmart. But the company’s evolving policies signal a broader business strategy.

Probably more than any other retailer, Walmart serves Americans of every socio-economic and cultural stripe, which means that any public policy stance the company takes will inevitably alienate many. And while it remains a dominant force in rural America, Walmart is betting much of its future on growing its e-commerce business in East and West Coast cities and suburbs, where potential shoppers tend to hold more liberal views, including on the need for more gun restrictions.

With 1.5 million employees, Walmart is the largest private employer in the United States, most of them the cashiers and managers in its network of 4,000 stores. However, the company is also trying to build its online business to compete with Amazon by recruiting younger engineers and developers, who are attracted to companies that profess social values that reflect their own.

“Any decision that a company that is that big and that ubiquitous makes is going to please some people and upset others,” said Aron Cramer, chief executive of BSR, a nonprofit group that advocates for social responsibility in business. “It is extremely hard not to take action when people are dying at one of your stores.”

Mr. McMillon, who became chief executive in 2014, has tried to bridge these various constituencies. He is a Walmart lifer who began working for the company as a warehouse employee when he was still in high school. In 2017, he was critical of President Trump’s comments after the violent rallies in Charlottesville, Va. But he has also emphasized his roots growing up in Arkansas, noting on Tuesday that he was a gun owner himself and acknowledging that the new policies may rankle many customers.