How can I change the nametag of a villager using commands

Is it possible to change the nametag of a villager using commands in Minecraft?


You need to use the NBT component CustomName

So to change name of an already existing villager you do entitydata @e[type=villager,c=1] {CustomName:"New Name"}

Also, to make the name always visible and not only when looked at you can add CustomNameVisible:1b to the NBT as well.