Treatment depends on the cause.
Exercise, particularly aerobic exercise is an effective treatment for erectile dysfunction.
When pharmacological methods fail, a purpose-designed external vacuum pump can be used to attain erection, with a separate compression ring fitted to the penis to maintain it. These pumps should be distinguished from other penis pumps (supplied without compression rings) which, rather than being used for temporary treatment of impotence, are claimed to increase penis length if used frequently, or vibrate as an aid to masturbation. More drastically, inflatable or rigid penile implants may be fitted surgically. Medications carry risk of priapism.
All these mechanical methods are based on simple principles of hydraulics and mechanics and are quite reliable, but have their disadvantages.