The Hammers will also be able to buy 23-year-old striker for an undisclosed fee, the club said in a statement.
"It's great to be here at West Ham and all signed up - I just can't wait to get started now," Carroll said. "I want to be playing games and obviously hoping to score some goals. I know the manager [Sam Allardyce] well and some of the lads, so it is nice for me to come to a place where I know people.
"I'm hoping to add a lot of goals and create a few chances. I know Sam from Newcastle and he was a massive reason for me coming. When I worked with him at Newcastle it was great so it was a no-brainer really."
Carroll joined Liverpool for a reported £35m in January 2011, a record fee for a British player. But he struggled for form and appeared to have been further marginalised by the arrival of new manager Brendan Rodgers in the summer.
Hammers boss Allardyce insisted that the former Newcastle player's all-round skills would benefit the promoted Championship club.
"I think for all parties this is a great signing," he said. "Andy is an all-round footballer, but because he is 6'3" and one of his strengths is his aerial power, everybody dismisses the ability he possesses on the floor.
"Hopefully he can score goals for us and we will be in a very good position at the end of the year in the Barclays Premier League."
Left-back George McCartney (ankle) and centre-halves James Collins (calf) and Winston Reid (knee) face late fitness tests after picking up knocks against Swansea last weekend.
Midfielder Jack Collison remains sidelined with a knee problem but the likes of Jussi Jaaskelainen, Guy Demel, Mark Noble, Mohamed Diame and Matt Jarvis will return after they were rested for the midweek Capital One Cup win over Crewe.
FULL TEAM NEWS: