Sudo: command not found


I’m trying to configure the hosts file as per the doc:

echo www.localhost.local | sudo tee -a /etc/hosts

But I’m getting “/bin/bash: sudo: command not found”

If I remove the sudo then I get a permission error. Any idea what’s up?


What container are you using?


Sorry for the late reply. Here’s the job description:

    working_directory: ~/app
      - image: node:8.1.4
      - image: circleci/ruby:2.2.7
      - image: redis:3.0.7

      - checkout
      - run: echo www.localhost.local | sudo tee -a /etc/hosts
      - run: echo api.localhost.local | sudo tee -a /etc/hosts
      - run:
          name: install-npm
          command: npm install -g npm
      - run:
          name: install-phantom
          command: sudo curl --output /usr/local/bin/phantomjs
      - run:
          name: setup-db
          command: bundle exec rake db:drop db:create db:migrate


You’re using the official Node Docker image which is based on a Docker image called buildpack-deps (specifically, the Debian Jessie version). The buildpack Docker image does not have sudo installed, which is not surprising since most Docker images run as root by default until told to switch to another user and group.

Since the Node Docker image doesn’t switch the user or group (though it does create both), you’re actually still running as root throughout the execution of the steps. In other words, you should be able to remove sudo and it will work just fine.

If you would like to use sudo, you’ll either need a separate run step or create a Docker image on top of the Node image that contains sudo.

  - run: apt-get install -y sudo


FROM node:8.1.4
RUN apt-get install -y sudo
CMD ["node"]

As an aside, based on your configuration file above, it looks like you’re trying to use both Node and Ruby in the steps. I believe you’ll run into an issue because your commands are going to execute inside the container based on Node; the Ruby and Redis images will be loaded separately. What you probably want to do instead is create a custom image that includes both Node and Ruby. That will allow you to call both Ruby and Node commands.


Thanks for the reply David! I’ll try installing the package. Without sudo it gave a permission error.

Do you have doc on creating custom images?


@blarralde here it is:


Thank you!


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.