Castro Alves was born in the town of Curralinho, in the Brazilian state of Bahia, to Antônio José Alves, a doctor, and Clélia Brasília da Silva Castro, one of the daughters of José Antônio da Silva Castro, a prominent fighter in the 1821–23 Siege of Salvador. In 1853, he was sent to study in the Colégio Sebrão, run by Abílio César Borges, the Baron of Macaúbas. There, he met and befriended Ruy Barbosa. In 1862 he moved to Recife to study at the Faculdade de Direito do Recife, but he was rejected twice. He was not able to join the college until 1864, there meeting Tobias Barreto and José Bonifácio the Younger. They heavily influenced Alves' writing style, and he, in turn, influenced them both. His father died in 1866 and shortly after, he met the Portuguese actress Eugênia Câmara, and started dating her. In 1867 Alves returned to Bahia with Câmara and wrote his drama Gonzaga, ou A Revolução de Minas, based on the life of the Luso-BrazilianNeoclassic poet Tomás António Gonzaga and his participation in the failed 1789 Minas Conspiracy. In the following year, he and Câmara went to São Paulo, where he entered the Faculdade de Direito da Universidade de São Paulo and once more met Ruy Barbosa. There he also befriended Pedro Luís Pereira de Sousa and wrote a poem named "Deusa incruenta", based on Sousa's work "Terribilis Dea". His play Gonzaga was performed at the end of 1868. It was well received by critics and public alike, but Alves was sad because his romantic engagement with Eugênia Câmara had terminated. During a hunting trip in the same year, Alves received an accidental shotgun wound in his left foot, which had to be amputated due to the menace of gangrene. However, a prosthesis was made for him, and thus he was able to walk again. He spent 1870 in his home-state of Bahia, trying to recover from the tuberculosis he got while in São Paulo. Also in 1870, Alves published the poetry book Espumas Flutuantes – the only work he published during his lifetime. All his other works were published posthumously. Alves' attempts to mitigate the tuberculosis were in vain; he died on 6 July 1871, in the city ofSalvador, at 24.
Alves also translated into Portuguese many poems by Victor Hugo, and Lord Byron's "Darkness" and "Lines Inscribed Upon a Cup Formed from a Skull". They can be found on Espumas Flutuantes.
Alves was portrayed by Paulo Maurício in the 1949 filmVendaval Maravilhoso, loosely based on Jorge Amado's 1941 book The ABC of Castro Alves, and by Bruno Garcia in Silvio Tendler's 1999 documentary .