From The Fellowship of the Ring, it is in a letter from Gandalf to Frodo at the Prancing Pony. Also, Bilbo (who wrote it) recites it at the Council of Elrond.

All that is gold does not glitter,
Not all those who wander are lost;
The old that is strong does not wither,
Deep roots are not reached by the frost.
From the ashes a fire shall be woken,
A light from the shadows shall spring;
Renewed shall be blade that was broken,
The crownless again shall be king.

This is also in the “The Return of the King” movie, quoted by Arwen, when she is trying to get her father to reforge the Sword of the Kings.

Research: legolas19 and royal_elf_maiden333
Editing: Hathaldir