Device to power either a red LED or a green LED
You mention an IO pin; this is how you could do it with one IO pin if you are using a microcontroller (assuming one that uses 5V logic):
simulate this circuit – Schematic created using CircuitLab
When the IO pin is 5V, D2 will light up; when the IO pin is 0V, D1 will light up.
Note that you will have to calculate the actual resistor values; different types and colours of LED require different resistors. There are plenty of examples about that show how to calculate these values.
Also, make sure you don't sink/source too much current; the maximum current an IO pin can handle varies from microcontroller to microcontroller.
simulate this circuit – Schematic created using CircuitLab
You could also try this.
simulate this circuit
This would also work.
simulate this circuit
A collection from another thread, posted here for the middle schematic. Pin 6 would be the GPIO pin. For better brightness matching, swap the red and green LED positions.