U.S. stocks gained sharply on Tuesday after Australia became the first G20 country to raise interest rates since the onset of the financial crisis, and on optimism for a strong U.S. earnings season.

The rate hike by Australia's central bank was taken as a signal the global economy was recovering. Equities were also lifted by gains in commodity prices as the U.S. dollar fell against a basket of currencies.

Shares in the basic materials sector led the way, with aluminum producer Alcoa Inc gaining 4 percent to $13.96. Alcoa, a Dow component whose shares were up strongly for a second straight day, will announce quarterly results on Wednesday, kicking off the earnings season. Analysts were optimistic that quarterly revenues will be broadly stronger.

The Australian central bank painted an extremely positive picture of the global economy moving forward ... about how good the Chinese economy is doing and how economic activity is picking up worldwide, said Stephen Massocca, managing director at Wedbush Morgan in San Francisco.

It legitimized those that have been calling for a vigorous expansion of the economy.

The Dow Jones industrial average <.DJI> was up 152.51 points, or 1.59 percent, at 9,752.26. The Standard & Poor's 500 Index <.SPX> rose 17.71 points, or 1.70 percent, at 1,058.17. The Nasdaq Composite Index <.IXIC> gained 38.57 points, or 1.86 percent, at 2,106.72.

Australia's central bank raised a key lending rate and said it was safe to pull back on stimulus spending. It is the first central bank of the Group of 20 top developed and emerging economies to raise rates.

Caterpillar Inc , the world's largest maker of earth-moving equipment, added 2.4 percent to $52.00 and was the top boost to the Dow industrials.

Freeport-McMoRan Copper & Gold Inc shot up 4.3 percent to $70.20 as benchmark U.S. gold futures soared to an all-time high. Gold rose to $1,043.70 an ounce, also on the back of the weak dollar.

Among active issues, Microsoft Corp gained 1.7 percent to $25.06 after introducing new software for mobile phones to compete with Apple Inc's iPhone. Apple shares rose 1.9 percent at $189.50, leading the Nasdaq index higher.

The PHLX semiconductor index <.SOXX> was up 2.4 percent after research firm Gartner said global semiconductor revenue could increase about 10 percent next year after two years of declines as new computers and smartphones boost chip demand.

On the downside, Boeing Co , fell 0.5 percent to $52.01, becoming the only decliner on the Dow index, after the plane maker announced another delay for its jumbo aircraft.

(Editing by Leslie Adler)