There are ibus and fcitx almost people used for chinese pinyin input method.
- ibus which I think more quick introduces first
You can avoid install ibus if there has been installed on ubuntu
sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4
change to ibus input program
im-config -s ibus
install google pinyin
sudo apt-get install ibus-pinyin
Restart the computer and conduct the below command
sudo ibus-setup
setup window will occurs, then add the chinese-pinyin will be ok
Activate the pinyin input
Setting->Region & Language -> Input Sources.
add Chinese and set to the first location, the setting icon will on top right corner of screen.
可以参考http://ubuntuhandbook.org/index.php/2016/07/2-best-chinese-pinyin-im-ubuntu-16-04/