How can I color a Banana?
Your approach is conceptually correct, you are only missing texture coordinates.

You can even skip the gradient texture and use raw UVs.

The most accurate method is to unwrap you mesh and make a proper UV map, but if you want to skip it, since the banana is an elongated almost-linear shape you can approximate it by using basic Generated texture coordinates.

They won't be as accurate as a proper manual UV mapping, but may do a passable job with less work.

Just use a Converter > Separate XYZ node to get the Y component of your Generated texture coordinates, then run those through the color ramp.