You can although the specifics depend a lot on what you're swtiching from. A mechnical engineer, an accountant, a history teacher and a blue-collar worker will need to approach this in very different ways.
I'd recommend finding something that combines programming and whatever your prior career has been, so you can bridge the gap.
I moved from teaching to coding by first working on open source teaching software in my spare time, then using it as part of my teaching work, then getting a junior coding job at a university. I was a better teacher because of the software I was making, and I was a more attractive junior hire due to my domain knowledge.
Code at home --> Use project at old job --> Use domain knowledge plus project to land first coding job --> Coding career :)
I moved from teaching to coding by first working on open source teaching software in my spare time, then using it as part of my teaching work, then getting a junior coding job at a university. I was a better teacher because of the software I was making, and I was a more attractive junior hire due to my domain knowledge.
Code at home --> Use project at old job --> Use domain knowledge plus project to land first coding job --> Coding career :)