'command not found: wrangler after installation of wrangler

I am trying to install the Cloudflare wrangler in ubuntu and I am able to install using normal command but when I use wrangler --version I am getting an error wrangler command not found and I have installed wrangler on the root using this command

basically i am trying to install

I have also used normal command npm i @cloudflare/wrangler

sudo npm install @cloudflare/wrangler -g --unsafe-perm=true --allow-root
wrangler --help (getting the above-mentioned error)
wrangler generate my-worker (getting the above-mentioned error)
but when i am using npx wrangler generate my-worker i am able to create the project but when i am running 
wrangler preview(same error so don't know how to solve this issue)

I am using Node version v10.10.0 and npm version is v6.13.6



Solution 1:[1]

Your installation of wrangler was local to the project you're in, in order for the wrangler command to work, it needs to be installed globally. npx runs the local project installation of wrangler, that is why that command works.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 carl