Donald Trump's comments came as he started a trip from New Jersey to address a campaign rally in New Hampshire.

US President Donald Trump said on Thursday he supports meaningful background checks for gun buyers, but he said that those responsible for recent mass shootings were mentally ill and the United States should build more mental institutions.

Donald Trump said he had been speaking with Senate majority leader Mitch McConnell and many other Republicans about the problem of gun violence, and "they don't want to have insane people, dangerous people, really bad people having guns."

"We don't want crazy people owning guns," the president told reporters in Morristown, New Jersey. "It's them. They pull the trigger. The gun doesn't pull the trigger. They pull the trigger. So we have to look very seriously at mental illness."

Donald Trump is under pressure to curb gun violence following two mass shootings that killed dozens of people this month in Texas and Ohio. His comments came as he started a trip from New Jersey to address a campaign rally in New Hampshire.

"We're looking at the whole gun situation," Donald Trump said when asked whether he was pressing Republicans on tougher background checks for gun buyers.

Later on Thursday at a rally in Manchester, New Hampshire, Donald Trump said it was necessary to consider building new institutions for the mentally ill.

"We have to do it. At the same time, we will be taking mentally deranged and dangerous people off of the streets so we won't have to worry so much about that. It's a big problem," Donald Trump said.

In his comments in New Jersey, Donald Trump said many US mental institutions were closed in the 1960s and 70s and their patients released onto the streets.

"We can't let these people be on the streets," Trump said.

A move toward deinstitutionalisation for the mentally ill began in the 1960s. It gathered force with court rulings in the 1970s. In a landmark case in 1975, the US Supreme Court ruled that a person had to be a danger to himself or to others to be confined.