1

I am a beginner who just installed ubuntu 18.04 just fews days ago, and I am currently studying how to do everything from the terminal.

Chrome is a necessary application for me, for example, and I have already known how to run it by using the command line like/opt/google/chrome/chrome, which is the default path to chrome. But for Firefox, which was installed initially, I just need to type firefox and the browser works just fine.

And now I'm wondering if I can open Chrome in a similar way rather than typing the complicated path. Anyone has ideas?

4

There are different ways to customize the name by which you can launch an application:

Method 1 - Create an alias Next to all options given in the other answers, a convenient way to make it easier for you to start Chrome from the command line, and which does not require to be administrator, is to create an alias:

alias chrome=/opt/google/chrome/chrome

Add this command to your .bashrc file (already, some other aliases are defined there), so it is available anytime.

Method 2 - Create a symlink also does not require root permissions: you can create your personal bin folder in your home directory. There, create a symbolic link to the executable of Google Chrome as:

ln -s /usr/bin/google-chrome ~/bin/chrome

On Ubuntu, a local bin folder is automatically added to the PATH. After creating the bin folder, it will take only effect after your next log in.

Method 3 - Create a systemwide symlink If the change is to affect all users, create an appropriately named symlink in /usr/bin. As mentioned in the other answers, a symlink may already be available. If you prefer the shorter name chrome, feel free to create an additional symlink as

sudo ln -s /usr/bin/google-chrome /usr/bin/chrome

or rename the existing symlink.

  • To be thorough there is a 4th method as posted by christian: adding the path to $PATH – karlsebal Feb 15 at 11:51
  • 1
    @karlsebal, agree this is a method, but it is not the best. One should not have to add an entry to the PATH for each individual application. – vanadium Feb 15 at 14:09
  • hash -r rereads the $PATH so bash knows the new contents of ~/bin – Thorbjørn Ravn Andersen Feb 15 at 15:13
  • chrome and chromium are distinct builds; I wouldn't suggest using one name as an alias for the other. – Peter Cordes 2 days ago
  • @PeterCordes For sure it should be "chrome=". Thank you, I have corrected this. – vanadium 2 days ago
4

TL;DR

For deb-packaged Google Chrome you can simply use google-chrome (or google-chrome-stable) command in the terminal.

Details

On my system I have stable version of Google Chrome 80 installed.
Its package name is google-chrome-stable, its binary files may be found by using

$ dpkg --listfiles google-chrome-stable | grep bin/
/usr/bin/google-chrome-stable

but really this file is a symlink to the location which you have mentioned (/opt/google/chrome/google-chrome):

$ ls -al /usr/bin/google-chrome-stable
lrwxrwxrwx 1 root root 32 Feb 13 07:04 /usr/bin/google-chrome-stable -> /opt/google/chrome/google-chrome

The /usr/bin is usually added to the PATH variable by default. So it is not really needed to add /opt/google/chrome/google-chrome to the PATH by hand.

For more complicated applications and their desktop- and executable files you can use methods from my other answer.

1

export PATH=$PATH:/opt/google/chrome/chrome

This will allow you to type chrome in your terminal to launch it.

This works by setting your path variable to itself and then appending :/opt/google/chrome/chrome

  • thanks a lot! i think this statement should work by putting it into the profile, like Christian said. Anyway, thanks for your help. – Liu Ramyon Feb 15 at 4:41
  • 2
    This is not really needed as /usr/bin/google-chrome-stable and /opt/google/chrome/google-chrome are symlinks, while /usr/bin is already in PATH. – N0rbert Feb 15 at 10:08
1

This is what the $PATH variable is for. When you're able to call firefox (or gedit, or whatever) by name, without referencing an absolute path, that's usually because it's in /usr/bin/ and /usr/bin/ is in your $PATH by default.

You can add an export statement to your .profile (so it's persistent) and reload it with:

echo 'export PATH=$PATH:/opt/google/chrome' >> ~/.profile
source ~/.profile

And then you can call Chrome with the simple chrome command in terminal. You can also go to Settings > Keyboard Shortcuts and set up a keyboard shortcut so you can open it without the terminal at all, or even set it as a startup application so it opens by default on login.

  • This is not really needed as /usr/bin/google-chrome-stable and /opt/google/chrome/google-chrome are symlinks, while /usr/bin is already in PATH. – N0rbert Feb 15 at 10:07
  • this depends on the installation method. The symlink in /usr/bin is not guaranteed to be there. – karlsebal Feb 15 at 11:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.