Ian David Long was a “loner” who served five years in the US Marine Corps as a machine gunner — with a tour in Afghanistan — and may have been suffering from posttraumatic stress disorder, officials and his former roommate said Thursday.

Ventura County Sheriff’s deputies in April checked in with the troubled 28-year-old, who was living at his mother’s home in Newbury Park, Calif., and found him acting “somewhat irate, acting a little irrationally,” Sheriff Geoff Dean said at a press conference.

The heavily tattooed vet was evaluated by mental health professionals — but they concluded he didn’t need to be placed in a temporary psychiatric hold.

“I understand that was part of the discussion, they felt he might be suffering from PTSD based on the fact that he was a veteran,” Dean said.

The sheriff told reporters a motive in the Thousand Oaks mass shooting has not yet been determined.

“Obviously, he had something going on in his head that would cause him to do something like this,” said Dean. “So, he obviously had some sort of issues.”

Cops were also called to the home earlier this year by a neighbor who complained of loud noises coming from inside.

“It sounded like he was tearing down the walls of the house,” Tom Hanson told local network KTLA. “It would start and then it would stop . . . and then it would get really loud and I hear this shouting. I thought, ‘Man, what’s going on out here?’ . . . I mean, it’s a quiet neighborhood.”

Hanson said Long had been living at his mom’s house with their three dogs for the past six to eight years and that neighbors “knew he had issues.”

Another neighbor, Richard Berge, who is a friend of Long’s mother, Colleen Long, said she was worried about her son.

“She was . . . kind of beside herself, she didn’t know what to do because he wouldn’t get help,” Berge told CNN.

Dean said investigators were waiting on a search warrant to scour the Newbury Park home, which is located about five miles from Borderline Bar & Grill — the popular Thousand Oaks bar where Long gunned down 12 people.

A cousin of the gunman, AJ Schramm, said Colleen Long was recently “venting” at a family wedding about problems she was having with her son, CBS News reported.

There were rumors among the family that Long suffered from PTSD but Schramm said he didn’t see him exhibit any unusual behavior. Long’s father died from cancer early in his life, the cousin said.

Long had no criminal record but some minor traffic infractions, including an arrest for speeding in Ventura County in 2013, according to NBC News. He was the victim of a battery at a different bar in Thousand Oaks in 2015, Dean said.

As a corporal in the Marines from 2008 to 2013, Long racked up numerous awards and commendations, including a Combat Action Ribbon and Marines Corps Good Conduct Medal. He handled heavy machine guns in direct combat and did a stint in Afghanistan for seven months between 2010 and 2011. He last served in Kaneohe Bay, Hawaii.

“The Marine Corps extends its deepest condolences to the families of the victims in this senseless tragedy,” the Marines said in a statement.

Long’s former roommate, Blake Winnett, told The Post that he knew Long did two or three tours but that he was mum on his service.

The two lived together twice in 2012 and 2014 in Simi Valley and Reseda, a neighborhood in Los Angeles.

“He was kind of weird. He always locked himself in his room, he was always by himself,” said Winnett. “I didn’t really know him very well.”

Winnett, 35, said he never witnessed Long get violent. But he did have some odd habits.

“He would go to the gym and then he would, I guess, try to learn dance moves or something,” he recalled. “He would close the garage and be playing music and dancing in there, like sweating. I . . . would be like, ‘What are you doing?’ ”

He and Long had hung out at Borderline before.

Long was a student at California State University Northridge from 2013 to 2016 and was majoring in athletic training, school officials said. But he never graduated, because he couldn’t handle the responsibilities.

“I am graduating with a B.S. in Athletic Training in two months. I found out a little too late that just wasn’t the job for me,” he wrote on a special forces forum called Shadowspear in March 2017, CNN reported.

“Maybe the ego got the better of me but it took only one time for a 19 year old D-2 athlete to talk down to me and tell me how to do my job that I realized this wasn’t the career I wanted to head.”