Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

SuSE's package manager zypper is able to create repository file in /etc/zypp/repos.d/.

zypper -n rr myrepo
zypper -n ar -f http://path/to/myrepo myrepo

I'm looking for an equivalent tool do the same thing for centos. I've checked the man page of yum, but it seems yum is not capable to do that. Currently I have to write the following hard code to create a repository file for centos.

echo "[myrepo]
name = My Repository
baseurl = http://path/to/myrepo
proxy = _none_
gpgcheck = 0
metadata_expire = 300
fastestmirror_enabled = 1
failovermethod = roundrobin
priority = 1
enabled = 1
retries = 5
timeout = 10" >/etc/yum.repos.d/myrepo.repo

It'd be great, if I can write two line code as zypper to make my job done.

share|improve this question
It might not be what you're looking for, but most of those lines are unnecessary. You can get by with just the first, third, and tenth lines. – devicenull Mar 19 '14 at 3:37
Since all of those values are user defined, this utility would need to take them as command-line input and just regurgitate it in VAR=VALUE format. Seems kind of silly to have a special purpose tool to do what you've already done with echo. – Aaron Copley Mar 21 '14 at 17:05
up vote 2 down vote accepted

Two lines, you say?! Here's a one-line function in bash that will do 99% of what you want:

function add-repo() { reponame=$1; url=$2; echo -e "[$reponame]\nbaseurl=${url}\nenabled=1\n" > /etc/yum.repos.d/$1.repo;}

usage: add-repo repo_name repo_url

Or a more human-readable formatting:

function add-repo() {

  echo -e "[$reponame]\nbaseurl=${url}\nenabled=1\n" > \

Of course, adjust as you see fit. If you're talking about the other end of maintaining a repository, look at createrepo.

share|improve this answer
It seems not to have a built-in util to fulfill my purpose. I think your answer is right now the best one. – stanleyxu2005 Mar 22 '14 at 13:57

take a look at dag createrepo package available on rpmforge:

this package will give you all tools to fullfill your needs

hoping this helps,

share|improve this answer
There is no need to use third-party repositories when createrepo is available in the regular ones. – dawud Mar 21 '14 at 17:17
createrepo doesn't do what OP is asking. – Aaron Copley Mar 21 '14 at 17:56

If you are trying to configure an in-house repository (a very typical scenario) then you would be best off creating an RPM package to deploy the repository configuration. This is the standard approach used by just about every other major third party EL based (RHEL, CentOS, Scientific Linux) repository including epel, remi, ius and rpmforge.

This is the same approach I've used in house for distributing our internal repository along with the relevant GPG signing key. For example I have a sources folder for our EL5 machines:

[linuxadm@machine]# ls -1 /home/linuxadm/rpmbuild/SOURCES/XXXXX-release-5.0.0

And the repo file contents:

[linuxadm@machine]# cat /home/linuxadm/rpmbuild/SOURCES/XXXXX-release-5.0.0/XXXXX.repo

And the SPEC file to build the whole thing:

Name:           XXXXX-release
Version:        5.0.0
Release:        1
Summary:        XXXXX repository configuration

Group:          System Environment/Base
License:        XXXXX
URL:            http://www.domain.ext
Source0:        %{name}-%{version}.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch

This package contains the XXXXX repository GPG key as well as configuration for yum.

%setup -q


rm -rf %{buildroot}

mkdir -p -m 755 %{buildroot}%{_sysconfdir}/pki/rpm-gpg
mkdir -p -m 755 %{buildroot}%{_sysconfdir}/yum.repos.d
install -m 644 XXXXX.repo  %{buildroot}%{_sysconfdir}/yum.repos.d/XXXXX.repo
install -m 644 RPM-GPG-KEY-XXXXX %{buildroot}%{_sysconfdir}/pki/rpm-gpg/RPM-GPG-KEY-XXXXX

rm -rf %{buildroot}

%config(noreplace) /etc/yum.repos.d/*

* Fri Mar 07 2014 First Last <email@domain.ext> - 5.0.0-1
- Initial Package

Once you have the RPM package it can be placed inside of the repository for which it belongs. Use createrepo --update [folder] to rebuild your repository metadata as needed. After that all you have to do to install your repository then is rpm -ivh http://repo.domain.ext/path/to/file/XXXXX.rpm and all configuration is automatically placed on the system.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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